Jump to content

[SOLVED] PHP generated tables


lil_bugga

Recommended Posts

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> &#163;".$item_price."</td>\n
			</tr>\n
		</table>\n";
	}

}

Link to comment
Share on other sites

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
Share on other sites

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 :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.