whiskedaway Posted November 18, 2009 Share Posted November 18, 2009 I'm really stuck, so I'm hoping someone might be able to help. I'm using PHP5 and I can't work out how to get each different row to display. Currently the first row displays over and over again until there are no more rows left in the table. So far this is what I've done: <?php include("credentials.inc"); $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); $sql = "SELECT o.orderID, i.sku, i.quantity, o.staffID FROM Orders o, ItemsOrdered i WHERE o.orderID = i.orderID"; $result = mysqli_query($cxn, $sql) or die ("Couldn't execute query."); $num = mysqli_num_rows($result); $rowname = mysqli_fetch_assoc($result); extract ($rowname); ?> <table width="250" border="0" align="center" cellpadding="2" cellspacing="2"> <tr><td><strong>OrderID</strong></td><td><strong>SKU</strong></td><td><strong>Quantity</strong></td><td><strong>StaffID</strong></td></tr> <?php $i=0; while ($i < $num) { //something here to change the values of $orderID, $sku, $quantity and $staffID ?> <tr><td><?php echo $orderID; ?></td><td><?php echo $sku; ?></td><td><?php echo $quantity; ?></td><td><?php echo $staffID; ?></td></tr> <?php $i++; } ?> </table> Hope someone can help! Link to comment https://forums.phpfreaks.com/topic/181956-solved-how-to-display-mysql-table-data-in-a-table/ Share on other sites More sharing options...
rajivgonsalves Posted November 18, 2009 Share Posted November 18, 2009 this should work <?php include("credentials.inc"); $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); $sql = "SELECT o.orderID, i.sku, i.quantity, o.staffID FROM Orders o, ItemsOrdered i WHERE o.orderID = i.orderID"; $result = mysqli_query($cxn, $sql) or die ("Couldn't execute query."); $num = mysqli_num_rows($result); ?> <table width="250" border="0" align="center" cellpadding="2" cellspacing="2"> <tr><td><strong>OrderID</strong></td><td><strong>SKU</strong></td><td><strong>Quantity</strong></td><td><strong>StaffID</strong></td></tr> <?php while ($rowname = mysqli_fetch_assoc($result)) { extract ($rowname); //something here to change the values of $orderID, $sku, $quantity and $staffID ?> <tr><td><?php echo $orderID; ?></td><td><?php echo $sku; ?></td><td><?php echo $quantity; ?></td><td><?php echo $staffID; ?></td></tr> <?php } ?> </table> Link to comment https://forums.phpfreaks.com/topic/181956-solved-how-to-display-mysql-table-data-in-a-table/#findComment-959752 Share on other sites More sharing options...
whiskedaway Posted November 18, 2009 Author Share Posted November 18, 2009 Wonderful, it does, thank you. Link to comment https://forums.phpfreaks.com/topic/181956-solved-how-to-display-mysql-table-data-in-a-table/#findComment-959755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.