Jump to content

Tables


SkyRanger

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.