Jump to content

Tables Tables


phpbeginner

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]
Link to comment
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
Link to comment
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!
Link to comment
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 :)
Link to comment
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]
Link to comment
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...
?>
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.