Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- try {
- $con= new PDO('mysql:Localhost;dbname=DB_Name', "username", "password");
- $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $query =
- "SELECT vehicle_plate as 'Plate',
- vehicle_color as 'Color',
- vehicle_model as 'Model',
- vehicle_ownername as 'Owner Name',
- vehicle_impoundedTill as 'Release Date'
- FROM vehicles where vehicle_isImpounded = true ";
- //SQL query only shows if cars are Impounded
- //first pass just gets the column names
- print "<table> ";
- $result = $con->query($query);
- //return only the first row (we only need field names)
- $row = $result->fetch(PDO::FETCH_ASSOC);
- if ($row > 0){
- print " <tr> ";
- foreach ($row as $field => $value){
- print " <th>$field</th> ";
- } // end foreach
- print " </tr> ";
- //second query gets the data
- $data = $con->query($query);
- $data->setFetchMode(PDO::FETCH_ASSOC);
- foreach($data as $row){
- print " <tr> ";
- foreach ($row as $name=>$value){
- print " <td>$value</td> ";
- } // end field loop
- print " </tr> ";
- } // end record loop
- print "</table> ";
- else{
- echo 'There are no cars impunded'
- }
- } //end if
- } // end try
- catch(PDOException $e) {
- echo 'ERROR: ' . $e->getMessage();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement