Forum Moderators: coopster

Message Too Old, No Replies

Help with tables

         

andyk96

11:47 pm on Mar 25, 2006 (gmt 0)

10+ Year Member



Hi All,

I very new to the scripting world and I need some help. On my site I have a php search engine. I have changed the code to add thumbnails but my problem is that it lists all thumbnails in a row with 9 of them.

What I need is to have 3 rows and 3 columns. Any help would be great.

DrDoc

12:31 am on Mar 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you will need to do is add a break after every 3 thumbnails. I'm not sure if you have a certain wrapper around each thumbnail, or if you are using a table structure, or what's going on. If tables (which it sounds like) you will need to add "</tr><tr>" after every 3.

Use a counter and modulus ...

if($cnt % 3 === 0) echo "</tr><tr>";

dreamcatcher

9:14 am on Mar 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




<table>
<?php

$images_per_row = 3;
$count = 0;
$content = '<tr>';

$query = mysql_query("SELECT * FROM table") or die(mysql_error());

while ($row = mysql_fetch_assoc($query))
{
echo '<td></td>';

if (++$count % $images_per_row === 0)
{
echo '</tr>';

if ($count!=mysql_num_rows($query))
{
echo '<tr>';
}
}

}

if ($count % $images_per_row!== 0)
{
echo '</tr>';
}
?>
</table>

Try that.

dc

dreamcatcher

3:01 pm on Mar 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry.

$content = '<tr>';

should be:

echo '<tr>';

dc

andyk96

2:40 am on Mar 27, 2006 (gmt 0)

10+ Year Member



Well I tried it and I can't get it to work right. I have it do some at 2 in a row some at 3. I'm going to put some of the codde I have to see if that will help out. If you need to see more of the code to get more info, e-mail me and I can send you the file.

?>
<table bgcolor="#ffffff" width="700" border="0" cellspacing="10" cellpadding="0">
<tr>
<?
// Display the results

while ($arrayline < $matches && $arrayline < $result_limit)
{
$ipage = $output[$arrayline][0];
$score = $output[$arrayline][1];

print "<p></p>\n";
echo '<td valign="top"><b><font class="font1">P.'.$urls[$ipage].'</font></b><br><br><a href="#" onClick="Javascript:parent.nav.openPage('.$urls[$ipage].') ; parent.main.focus();return false "><img src="/cat/'.$CATALOG_NAME."/thumbnails/".$urls[$ipage].'.jpg"></a><br><br>';
print "<div class=\"result_title\">";

scriptmasterdel

2:15 pm on Mar 27, 2006 (gmt 0)

10+ Year Member



I would do it like this.


<table>
<?
$x=1;
while ($arrayline < $matches && $arrayline < $result_limit)
{
$ipage = $output[$arrayline][0];
$score = $output[$arrayline][1];

if($x%3==1)
{
if($x>1)
{
echo '</td></tr>';
}
echo '<tr><td>';
}
else
{
echo '</td><td>';
}
echo '<font class="font1">P.'.$urls[$ipage].'</font></b><br><br><a href="#" onClick="Javascript:parent.nav.openPage('.$urls[$ipage].') ; parent.main.focus();return false "><img src="/cat/'.$CATALOG_NAME."/thumbnails/".$urls[$ipage].'.jpg"></a><br><br>';
print "<div class=\"result_title\">";
$x++;
}
?>
</table>

let me know if this helps!

Del