Stephen68 Posted October 9, 2010 Share Posted October 9, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/215470-table-display/ Share on other sites More sharing options...
Pikachu2000 Posted October 9, 2010 Share Posted October 9, 2010 How many fields are you trying to display from each database record? Quote Link to comment https://forums.phpfreaks.com/topic/215470-table-display/#findComment-1120448 Share on other sites More sharing options...
Stephen68 Posted October 9, 2010 Author Share Posted October 9, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/215470-table-display/#findComment-1120449 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.