Andreycon Posted July 23, 2020 Share Posted July 23, 2020 Let's assume this is my table Name Amount Gender Stone Cold. 1245. Male Kingsley. 500 Male. Stone Cold 2367 Male Stone Cold. 5678. Male Now I want to print stone cold rows. Which is row 1,3 and 4 just exactly the same format with he above table. How do I get to do that. My code is <?php $id = $_SESSION['login']; $sqlB = "SELECT * FROM activities WHERE username=? ORDER BY No DESC LIMIT 10"; $stmtB = $connection->prepare($sqlB); $stmtB->bind_param('s', $id); $stmtB->execute(); $resultB = $stmtB->get_result(); while($rowB = $resultB->fetch_all(MYSQLI_ASSOC)){ foreach ($rowB as $out) { echo implode(' ', $out) . "<br>"; exit; } } //print_r($rowB); // exit; ?> I don't understand how to put each row for stone cold into HTML row. Please don't be annoyed by my question, I know its a simple stuff but I've tried several stuffs, I can't get what I need still. If I print $rowB I get all want from the database in arrays. Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/311208-how-to-print-out-multiple-rows-from-database/ Share on other sites More sharing options...
gw1500se Posted July 23, 2020 Share Posted July 23, 2020 (edited) Add: AND name='Stone Cold' to your WHERE clause in the query. Assuming 'name' is that column name. Edited July 23, 2020 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/311208-how-to-print-out-multiple-rows-from-database/#findComment-1579991 Share on other sites More sharing options...
Barand Posted July 23, 2020 Share Posted July 23, 2020 With mysqli, when you use prepare() you get a statement object. The fetch_all() method you are using is a mysqli result object method (You get a result object when you use mysqli query() ). mysqli was built by two teams of developers who never spoke to one another, and so you get one set of methods for statements and a completely different set for results. Use PDO and this mess goes away. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311208-how-to-print-out-multiple-rows-from-database/#findComment-1579992 Share on other sites More sharing options...
Andreycon Posted July 23, 2020 Author Share Posted July 23, 2020 (edited) 20 minutes ago, gw1500se said: Add: AND name='Stone Cold' to your WHERE clause in the query. Assuming 'name' is that column name. The $id is its name. So am indexing it with the name. It finds it but only output the first row but if I print $rowB I get all the rows for stone cold in arrays though Edited July 23, 2020 by Andreycon Quote Link to comment https://forums.phpfreaks.com/topic/311208-how-to-print-out-multiple-rows-from-database/#findComment-1579993 Share on other sites More sharing options...
gw1500se Posted July 23, 2020 Share Posted July 23, 2020 (edited) You don't need the 'while'. Do the 'fetchall' once then run your 'for' loop. Anyway, I agree with Barand, PDO is a better choice. Edited July 23, 2020 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/311208-how-to-print-out-multiple-rows-from-database/#findComment-1579994 Share on other sites More sharing options...
Andreycon Posted July 23, 2020 Author Share Posted July 23, 2020 Tanx all. I got an approach which now works echo "<table>"; foreach ($rowB as $row) { echo "<tr>"; foreach ($row as $column) { echo "<td>$column</td>"; } echo "</tr>"; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/311208-how-to-print-out-multiple-rows-from-database/#findComment-1579995 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.