image decoration in a table

i want to create a table with 4 cells

Page 1 of 1

4 Replies - 4568 Views - Last Post: 17 December 2005 - 02:18 PM Rate Topic: -----

#1 chitara   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 89
  • Joined: 16-December 05

image decoration in a table

Posted 17 December 2005 - 09:04 AM

Hello,

Hi everybody!! I m new in this forum and also new in php. I am facing some problems with my record-displaying from database.

i want to display my images with description in a table with 4 <td> in each <tr>

i am working with the following scripts.....


//----------------------------------------------

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="98%" id="AutoNumber1" height="270">

<?php

$query = "select * from job_foto where category = 'communication'";
$result = mysql_query($query);

$num= mysql_num_rows($result);
echo $num."<br>";
?>

<tr>
<?
while ($row = mysql_fetch_array($result))
{

for($i=0;$i<count($num);$i++)

{

for($j=0;$j<1;$j++) { //{


?>
<td class=body vAlign=middle width="24%" height="54">
<a class=lnk href='job.php' target=_top><img border="0" src="getfoto.php?id=<?php print $row["foto_id"]; ?>"><br>
<?php print $row["client"]; ?><br>
<?php print $row["job"]; ?></a>
</td>
<?
}

}
}
?>
</tr>
</table>

//----------------------------------


But this is showing all the data in a single <tr>
Please can any one help me !!!

Is This A Good Question/Topic? 0
  • +

Replies To: image decoration in a table

#2 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 250
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: image decoration in a table

Posted 17 December 2005 - 09:50 AM

Put your TR tags inside the for loop.

You'll also need to check the inner for loop variable $j to see when it reaches 3 (you're strarting at 0) and each 4 numbers after that, and break the inner for loop when it does.
Was This Post Helpful? 0
  • +
  • -

#3 Wizzy   User is offline

  • D.I.C Regular
  • member icon

Reputation: 6
  • View blog
  • Posts: 408
  • Joined: 20-November 05

Re: image decoration in a table

Posted 17 December 2005 - 11:29 AM

couldn't this be done with a foreach statement?

<?php

foreach($result as "<br>") {
echo "<tr><td>$num</td></tr>";
}

?>

Was This Post Helpful? 0
  • +
  • -

#4 PeterM   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-December 04

Re: image decoration in a table

Posted 17 December 2005 - 02:08 PM

<?
$count = 0; // initialise to 0
while ($row = mysql_fetch_array($result))
{
?>
<td class=body vAlign=middle width="24%" height="54">
<a class=lnk href='job.php' target=_top><img border="0" src="getfoto.php?id=<?php print $row["foto_id"]; ?>"><br>
<?php print $row["client"]; ?><br>
<?php print $row["job"]; ?></a>
</td>
<?
if($count == 3) // check if we're in the 4th loop (count = 3)
{
   echo "</tr><tr>";
   $count = 0; // reset count to 0 as we're in a new row
}

$count++; // add 1 to count
}
?>



Replace this in your existing code (between your <tr> and </tr>). This should fix your problem.

BTW: Welcome to dream.in.code!

PeterM

This post has been edited by PeterM: 17 December 2005 - 02:11 PM

Was This Post Helpful? 0
  • +
  • -

#5 Amorphous   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 44
  • Joined: 10-December 05

Re: image decoration in a table

Posted 17 December 2005 - 02:18 PM

it doesn't say he wants it to be in 3 colums per row...
I think Wizzy's method is the most efficient.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1