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