lil_bugga Posted May 18, 2009 Share Posted May 18, 2009 Hi, I've got my data currently displaying inside tables but currently they line up underneath each other. How can I change this so my items display 4 wide and as many down as is needed. The link shows you what I'm getting so far. http://ben.broxie.co.uk/benwoolner/littleshopper/showitems.php?subcat_id=1 // sets up queries $get_data_qry = "SELECT item_title, item_price, item_image FROM store_items ORDER BY id"; // sets up query calls $get_data_res = mysqli_query($mysqli, $get_data_qry) or die(mysqli_error($mysqli)); //get and show 1st level navigation if (mysqli_num_rows($get_data_res) < 1) { $display_content = "<p><em>Sorry, no categories to browse.</em></p>\n"; } else { while ($data = mysqli_fetch_array($get_data_res)) { $item_title = ucwords(stripslashes($data['item_title'])); $item_price = $data['item_price']; $item_image = $data['item_image']; $display_content .= " <table border=\"1\" width=\"180px\">\n <tr>\n <td><p class=\"centre\"><b>".$item_title."</b></p></td>\n </tr>\n <tr>\n <td><p class=\"centre\"><img src=\"".$item_image."\" height=\"127px\" width=\"157px\"></p></td>\n </tr>\n <tr>\n <td><b>Item Price:</b> £".$item_price."</td>\n </tr>\n </table>\n"; } } Link to comment https://forums.phpfreaks.com/topic/158625-solved-php-generated-tables/ Share on other sites More sharing options...
radi8 Posted May 18, 2009 Share Posted May 18, 2009 There may be an easier way, but try to make a table of tables, kinda like this (I did not run this, there may be errors...): <?php // sets up queries $get_data_qry = "SELECT item_title, item_price, item_image FROM store_items ORDER BY id"; // sets up query calls $get_data_res = mysqli_query($mysqli, $get_data_qry) or die(mysqli_error($mysqli)); //get and show 1st level navigation if (mysqli_num_rows($get_data_res) < 1) { $display_content = "<p><em>Sorry, no categories to browse.</em></p>\n"; } else { $counter=1; $display_content = "<table border=\"1\" width=\"180px\">\n"; while ($data = mysqli_fetch_array($get_data_res)) { $item_title = ucwords(stripslashes($data['item_title'])); $item_price = $data['item_price']; $item_image = $data['item_image']; if($counter==1)$display_content .= "<tr>\n"; $display_content .= "<td>\n"; $display_content .= " <table border=\"1\" width=\"180px\">\n <tr>\n <td><p class=\"centre\"><b>".$item_title."</b></p></td>\n </tr>\n <tr>\n <td><p class=\"centre\"><img src=\"".$item_image."\" height=\"127px\" width=\"157px\"></p></td>\n </tr>\n <tr>\n <td><b>Item Price:</b> £".$item_price."</td>\n </tr>\n </table>\n"; $display_content .= "</td>\n"; $counter++; if($counter >4){ $display_content .= "</td></tr>\n"; $counter=1; } } $display_content .= "</table>\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/158625-solved-php-generated-tables/#findComment-836596 Share on other sites More sharing options...
lil_bugga Posted May 18, 2009 Author Share Posted May 18, 2009 There may be an easier way, but try to make a table of tables, kinda like this (I did not run this, there may be errors...): <?php // sets up queries $get_data_qry = "SELECT item_title, item_price, item_image FROM store_items ORDER BY id"; // sets up query calls $get_data_res = mysqli_query($mysqli, $get_data_qry) or die(mysqli_error($mysqli)); //get and show 1st level navigation if (mysqli_num_rows($get_data_res) < 1) { $display_content = "<p><em>Sorry, no categories to browse.</em></p>\n"; } else { $counter=1; $display_content = "<table border=\"1\" width=\"180px\">\n"; while ($data = mysqli_fetch_array($get_data_res)) { $item_title = ucwords(stripslashes($data['item_title'])); $item_price = $data['item_price']; $item_image = $data['item_image']; if($counter==1)$display_content .= "<tr>\n"; $display_content .= "<td>\n"; $display_content .= " <table border=\"1\" width=\"180px\">\n <tr>\n <td><p class=\"centre\"><b>".$item_title."</b></p></td>\n </tr>\n <tr>\n <td><p class=\"centre\"><img src=\"".$item_image."\" height=\"127px\" width=\"157px\"></p></td>\n </tr>\n <tr>\n <td><b>Item Price:</b> £".$item_price."</td>\n </tr>\n </table>\n"; $display_content .= "</td>\n"; $counter++; if($counter >4){ $display_content .= "</td></tr>\n"; $counter=1; } } $display_content .= "</table>\n"; } ?> Thats worked really nicely, thanks for the help Link to comment https://forums.phpfreaks.com/topic/158625-solved-php-generated-tables/#findComment-836606 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.