Jump to content


Photo

Tables Tables


  • Please log in to reply
13 replies to this topic

#1 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 10 October 2006 - 05:06 PM

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 .....


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>";
 
}


#2 GremlinP1R

GremlinP1R
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts
  • LocationSouth Africa

Posted 10 October 2006 - 05:20 PM

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 = pathname;
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

#3 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 10 October 2006 - 05:24 PM

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"))

#4 GremlinP1R

GremlinP1R
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts
  • LocationSouth Africa

Posted 10 October 2006 - 05:37 PM

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


Okay that sould work!

#5 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 10 October 2006 - 05:40 PM

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 !

#6 GremlinP1R

GremlinP1R
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts
  • LocationSouth Africa

Posted 10 October 2006 - 05:43 PM

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


#7 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 10 October 2006 - 05:48 PM

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

#8 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 10 October 2006 - 06:01 PM

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.

<?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++;
}
?>

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


#9 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 10 October 2006 - 06:04 PM

That looks like what I am looking for ! Appreciate it !

#10 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 10 October 2006 - 06:25 PM

Sheeet ! I'm sure I erred somewhere.....this is what I ended up with but it displays 1 image per row.

{
	

	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++;
}
}


#11 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 10 October 2006 - 07:42 PM

Anyone have any ideas on this ?

Thanks In Advance !

#12 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 10 October 2006 - 09:55 PM

anyone ?

#13 Firemankurt

Firemankurt
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts
  • LocationWashington State

Posted 10 October 2006 - 11:33 PM

<?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...
?>

#14 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 11 October 2006 - 12:12 AM

Hmmmm.....really lost now as nothing is displaying and no errors.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users