Jump to content

Archived

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

phpbeginner

Tables Tables

Recommended Posts

What I am trying to do is show a row of 4 images across, start a new row, and then end the table when there is no more to display from my DB.
Here is a raw example of my code and with no luck .....


[sup]print "<div align=\"center\">
  <table width=\"100%\" cellspacing=\"2\" cellpadding=\"5\" bordercolordark=\"#000000\" bordercolorlight=\"#000000\">
    <tr bordercolor=\"#FFFFFF\">"
      ;
  print"
      <td width=\"100\">
        <div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">";

if (file_exists("$#############"))
{
print("<img src=\"#################"><br>$a_row[######]</td>");
}
else
{
print"</td>
    </tr>
  </table>";
}

print"<br>";
 
}[/sup]

Share this post


Link to post
Share on other sites
You lost me there with your coding.
Not sure how the pics work but I'm sure its almost the same as info.

Try this
$Pic = [color=red]pathname[/color];
echo"<tr><td>";
echo"$pic";
echo"</td><td>";
echo"$pic2";
echo"</td><td>";
echo"$pic3";
echo"</td><td>";
echo"$pic4";
echo"</td></tr>";

Okay dont need all the echo's

Share this post


Link to post
Share on other sites
Here's how the pics work. When I do add somethign to the database and then upload the pics, it just stores the link to the absolute path of the image for that record.

So this part of the code would appear as below:

if (file_exists("$abpath/path/to/image/$a_row[id]-1.jpg"))

Share this post


Link to post
Share on other sites
Okay well then this sould work.
$result= mysql_query("SELECT * FROM [color=red]table[/color]");
while ($row = mysql_fecth_array($result)){echo "<tr><td>$row['[color=red]row in tabels name[/color]'</td><td>[color=red]just repeat, when at number 4 close the line[/color]</td></tr>";}


Okay that sould work!

Share this post


Link to post
Share on other sites
Ahh, that's what I am doing but thought there was a better way of doing this. What if I have 100 items to display......thats a lot of code !

Share this post


Link to post
Share on other sites
okay well if you tell him <tr><td>$row</td><tr> in side of a table colum it will repeat for all until there are no more. But that will put one on each line

Share this post


Link to post
Share on other sites
Yes, I realize that......I have done this.

Does anyone know from the above script how I can create a table with an X # of thumbnails, showing rows of 4 and continuing until there are no more to display ?

Thanks in Advance

Share this post


Link to post
Share on other sites
When I use a table to do this with images and I want to break at the end of 4 images I keep a counter and then check the Modulus to make sure there is no remainder and then break on that.

[code]
<?php
// Images in an array or database whatever)
$images = aray("pic1", "pic2", "pic3", "pic4", "pic5");
echo "<table border=\"1\">";

$i = 1;
// Loop through the array for images
foreach($images as $filename) {
  // If i did this right, then if there is not a remainer then add the TR tags to drop to a new row.
  if($i % 4 <> 0) echo "</tr><tr>\n";

  // Display the image in a table cell
  echo "<td><img sr=\"{$filename}\" /></td>";

  // Increment counter
  $i++;
}
?>
[/code]

Now I might have it a bit wrong, but the idea is there :)

Share this post


Link to post
Share on other sites
Sheeet ! I'm sure I erred somewhere.....this is what I ended up with but it displays 1 image per row.

[code]{


echo "<div align=\"center\">
  <table width=\"100%\" cellspacing=\"2\" cellpadding=\"5\" bordercolordark=\"#000000\" bordercolorlight=\"#000000\">";
$i = 1;
if($i % 4 <> 0) echo "</tr><tr>\n";
  echo"
      <td width=\"100\">
        <div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">";

if (file_exists("$abpath/path to image/$a_row[id]-top.jpg"))
{
echo("<img src=\"http://$domain/path to image/$a_row[id]-top.jpg\" width=\"100\"><br>$a_row[#####]</td>");
$i++;
}
}[/code]

Share this post


Link to post
Share on other sites
<?php
// Query above already done
echo "<div align=\"center\">

  <table width=\"100%\" cellspacing=\"2\" cellpadding=\"5\" bordercolordark=\"#000000\" bordercolorlight=\"#000000\">";

$i = 0;
echo "<tr>\n";

while ($a_row= mysql_fetch_row($Result)){
  if($i == 4) {
echo "<tr>\n";
$i = 0;
}

echo"<td width=\"100\">
        <div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">";

if (file_exists("$abpath/path to image/$a_row[id]-top.jpg"))
{
echo("<img src=\"http://$domain/path to image/$a_row[id]-top.jpg\" width=\"100\"><br>$a_row[#####]</td>");
$i++;
}
}

echo "</table>";
// More php...
?>

Share this post


Link to post
Share on other sites

×

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.