Jump to content

Need help, PHP and Tables


gfX

Recommended Posts

Hello.

What I am trying to do, is have 12 total layouts showing.  3 rows of 4.

I am using tables for this, and it is generated using PHP.

 

	<table border="0" cellspacing="0" cellpadding="1" align="center">
		<?php
		        $sql = mysql_query("SELECT * FROM `layouts` ORDER BY `id` ASC");
				$i = 0;
        while ($r=mysql_fetch_assoc($sql)) 
            {
                $i++;
	$id = $r['id'];
                $title = $r['title'];
                $code = $r['code'];
                $thumbnail = $r['thumbnail'];
			if (($i == 5))
				{
					echo "<tr>";
				}
                echo "<td width='25%' align='center' valign='top'>
			<a href='http://www.layoutslife.com/code.php?id=$id'>
			<img src='http://www.layoutslife.com/thumbnails/$thumbnail' border='0' width='160' height='120' /></a>
			<br /><b>$title</b><br /></td>";
			if (($i == 5))
				{
					echo "</tr>";
				}

            
		}
    
    ?>


	</table>

 

That's the code I have, which I know is definitely wrong because it isn't working! Does anyone know how I can get this done?

Here is a screenshot of how it displays with my current code:

 

problemEa5k.gif

 

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/37113-need-help-php-and-tables/
Share on other sites

Soooooo..

 

	<table border="0" cellspacing="0" cellpadding="1" align="center">
	<tr>
		<?php
		        $sql = mysql_query("SELECT * FROM `layouts` ORDER BY `id` ASC");
				$i = 0;
        while ($r=mysql_fetch_assoc($sql)) 
            {
                $i++;
	$id = $r['id'];
                $title = $r['title'];
                $code = $r['code'];
                $thumbnail = $r['thumbnail'];
			if ($i > 0 && $i % 5 == 0) {
  				print "</tr><tr>";
}
                echo "<td width='25%' align='center' valign='top'>
			<a href='http://www.layoutslife.com/code.php?id=$id'>
			<img src='http://www.layoutslife.com/thumbnails/$thumbnail' border='0' width='160' height='120' /></a>
			<br /><b>$title</b><br /></td>";


            
		}
    
    ?>

		</tr>
	</table>

 

?? Almost there, Preview at: www.layoutslife.com

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.