Kenny_Luck Posted November 1, 2019 Share Posted November 1, 2019 so here the code that i am confusing the whole month , how can i get it to print out the filtered data $sql="SELECT COUNT(*) as conflicts FROM rental WHERE Dispatch < :dropoff AND Dropoff > :dispatch"; $stmt = $pdo->prepare($sql); $stmt->execute( [ 'dropoff' => $Dropoff, 'dispatch' => $Dispatch ]); im so frustrated on myself that cant do anything Quote Link to comment https://forums.phpfreaks.com/topic/309446-how-do-i-print-out-the-data-form-pdo/ Share on other sites More sharing options...
Barand Posted November 1, 2019 Share Posted November 1, 2019 https://phpdelusions.net/pdo Quote Link to comment https://forums.phpfreaks.com/topic/309446-how-do-i-print-out-the-data-form-pdo/#findComment-1571152 Share on other sites More sharing options...
chhorn Posted November 1, 2019 Share Posted November 1, 2019 (edited) Espacially this: https://phpdelusions.net/pdo#fetch as it looks like you have mostly anything else. Also have a look at print_r(), var_dump(), htmlspecialchars(), Template Engines and XSS (cross site scripting). Edited November 1, 2019 by chhorn Quote Link to comment https://forums.phpfreaks.com/topic/309446-how-do-i-print-out-the-data-form-pdo/#findComment-1571153 Share on other sites More sharing options...
Barand Posted November 1, 2019 Share Posted November 1, 2019 Not just fetch(), there are multiple options open, for example fetch() fetchAll() foreach ($stmt ...) Quote Link to comment https://forums.phpfreaks.com/topic/309446-how-do-i-print-out-the-data-form-pdo/#findComment-1571154 Share on other sites More sharing options...
ginerjm Posted November 1, 2019 Share Posted November 1, 2019 While reading the item linked to by Barand would be a great place to improve your PDO knowledge, a simple loop on a fetch is the usual way of outputting the results of a query. One problem with your query though is all you are asking for is a count of the rows that match your where condition. Don't you want so select some fields from those matching records to be displayed? After that you simply do this: echo "<table>"; while ($row = $stmt-fetch(PDO::FETCH_ASSOC)) { echo "<tr> <td>{$row['fieldname1']}</td> <td>{$row['fieldname2']}</td> <td>.....</td>.... </tr>"; } echo "</table>"; This will give you a nice html table of the results. You can add your own table headings (th tags) to improve it. And you could add some css code to make more improvements. Note - the "fieldname1 and "fieldname2" are made-up names for your query results. Obviously you would substitute your queried item names for the $row elements. PS - you should also add some error handling code to ensure that the query has actually run or that you have some results to be displayed before starting the loop. Quote Link to comment https://forums.phpfreaks.com/topic/309446-how-do-i-print-out-the-data-form-pdo/#findComment-1571162 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.