Jump to content

Table display


Stephen68

Recommended Posts

This may be in here already and I'm sorry for not being able to find it but..

 

I just want to display some information that I get from the database in a HTML table only using 2 columns.

Do I just set i=1 and run a if statement to see what column I am on? like

 

$i =0
While ($row = msyql_fetch_array($result)) {

    if ($i==0) {
        // start a new row
        echo "<tr>";
        $i = $i++;
    }else{
        //columns
        echo "<td>info</td>";
        $i=$i++;
   }

   if ($i < 2) {
     //end the row reset $i
     echo "</tr>";
    $i =0;
   }
}
           

 

Or something like that, am I heading in right direction?

 

Thanks Stephen

Link to comment
Share on other sites

Well right now there are only 6 lets say headings in the table. I would like to display them in a table 2 columns wide and how ever

many rows I need. I think I have it worked out though it might not be the best way of doing it. Now the problem I am having I guess

is with mysql since it  will not list all 6 headings.

 

Here is some of the code I'm using, please forgive me if you eyes bleed.

 

<?php
		  $i = 0; //place holder for creation of table
		  
		  //Strat loop for making 2 column table
		  while ($row = mysql_fetch_array($results)) {
			  //Check to see if $i is 0, if so start new row
			  if ($i == 0){
				  echo "<tr>\r";
				  $i= $i+1;
			  }else{
				  //columns
				  echo "<td>\r<div class='smallhead'>".$row['type_name']."</div>\r";
				  echo "<p>";
				  //Loop through all spring_sub_types names for this type
				  while ($sub_row = mysql_fetch_array($results_sub)) {
					  echo "\r<div id='items'>\r";
					  echo "<a href='item_display.php?subType=1'>".$sub_row['sub_type_name']."</a>\r";
					  echo "<br>\r";
				  }
				  echo "</div>\r";
				  echo "</p>\r";
				  echo "</td>\r";
				  $i = $i+1;
			  }
			  if ($i > 2) {
				  //end table row
				  
				  echo "</tr>\r";
				  $i = 0;
			  }
		  }
		  



?>

 

for some reason the while loop is not showing me all the information I get back from the query. I did a mysql_num_rows and it

tells me that it is getting all 6 headings so I'm not sure what it wrong. Should I not use the

 

while ($row = mysql_fetch_array($results)) {

 

any help would be great, thanks

 

Stephen

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.