SkyRanger Posted March 22, 2012 Share Posted March 22, 2012 This is more than a question than anything else: I am looking for a tutorial or something that will allow me to make tables with php and mysql for example what I need is: mysql data: table = links lid = 1 lname = Page 1 linkid = page.php lid = 2 lname = Page 2 linkid = page2.php etc and i am try to get it so if there is 2 pages then the table would do Page 1 Page 2 if 3 Page 1 Page 2 Page 3 so there are 2 lname(s)s per row and 1 in each column and it would keep building the table and rows as more lname(s) are added. Does anybody know where to find a tutorial on doing something like this. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/259515-tables/ Share on other sites More sharing options...
Drummin Posted March 22, 2012 Share Posted March 22, 2012 Saw all the big boys reading so I didn't reply earlier. I wouldn't approach this as amending table fields but instead inserting rows into your table. Keep the fields as: lid AUTO_INCREMENT lname varchar linkid varchar And add a new row for each page. http://www.tizag.com/mysqlTutorial/mysqlinsert.php Link to comment https://forums.phpfreaks.com/topic/259515-tables/#findComment-1330306 Share on other sites More sharing options...
SkyRanger Posted March 23, 2012 Author Share Posted March 23, 2012 Thats not what I needed but thanks anyhow, What I was looking for is a tutoriaI to output html rows and columns based on what is in the mysql example: <table style="width: 100%"> <tr> <td><a href= "<?php echo $linkid; ?>"><?php echo $lname; ?></a></td> <td><a href= "<?php echo $linkid; ?>">... $lname..</a</td> </tr> <tr> <td>....etc.....</td> <td> </td> </tr> </table> And if if was 4 it would fill the next td then 5 would make another tr and fill the first td and so on. Anybody know of an example that I could study on how to do this. Link to comment https://forums.phpfreaks.com/topic/259515-tables/#findComment-1330368 Share on other sites More sharing options...
Drummin Posted March 23, 2012 Share Posted March 23, 2012 Something like this should work. <?php echo "<table style=\"width:100%\">\r"; $x="1"; //$totalrows=mysql_num_rows($sql); //WHILE($row=mysql_fetch_array($sql)){ //I'll use sample total and WHILE loop and variables for test $linkid=9; $lname="Page Name"; $totalrows=25; WHILE($x<25){ if ($x==1){ echo "<tr>\r";} echo "<td><a href=\"page.php?id=$linkid\">$lname</a></td>\r"; $x++; if($x%4==0){echo "</tr><tr>\r";} }//WHILE LOOP //Clean up loose ends //Add table cells to finish row if(($totalrows%4)!="0"){ $remander=$totalrows%4; while($remander<4){ echo "<td> </td>\r"; $remander++; } //add the last tr if($remander=="4"){echo "</tr>\r";} }//if(($totalrows%4)!="0") echo "</table>\r"; ?> Link to comment https://forums.phpfreaks.com/topic/259515-tables/#findComment-1330375 Share on other sites More sharing options...
SkyRanger Posted March 23, 2012 Author Share Posted March 23, 2012 k, thanks Drummin, that gives me a really good starting point. Thanks for your reply. And by the looks of your code that would be exactly what I am looking for. Link to comment https://forums.phpfreaks.com/topic/259515-tables/#findComment-1330381 Share on other sites More sharing options...
Drummin Posted March 23, 2012 Share Posted March 23, 2012 I changed that last WHILE loop to while($remander<=4){ echo "<td> </td>\r"; $remander++; } I guess you'll figure out what works best. Link to comment https://forums.phpfreaks.com/topic/259515-tables/#findComment-1330382 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.