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
https://forums.phpfreaks.com/topic/23571-tables-tables/
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
https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107009
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"))
Link to comment
https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107012
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
https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107019
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
https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107038
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
https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107056
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
https://forums.phpfreaks.com/topic/23571-tables-tables/#findComment-107216
Share on other sites

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.