Jump to content

formatting recalled images


ksb24930

Recommended Posts

I am trying to format the images stored in a database into a table that is for pictures across, and how ever many rows it takes to display all the images. here is the code that doesn't work:

echo "<TABLE border=1 cellSpacing=0 cellPadding='5%'>
<TR><TD COLSPAN='6' ALIGN='MIDDLE'><font size='6'><b>Rowing Gallery</b></font></align><BR><BR><hr/></TD>
</TR>";
echo "</TR>
<table border='1' cellpadding='15' cellpadding='20%' ID='Table1'>
<tr>";



$count_sql = 'SELECT * FROM imagea';
$result = mysql_query($count_sql);


$num=mysql_numrows($result);



$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"image_id");

   
echo "<tr>

<td width='' bgcolor='' align='' valign=''>";
echo "<td><a href=index.php?iid=$id&tbl=imagea><img src='image.php?iid=$id&tbl=imagea' width=100 height=73 ></a></td>";
$i++;
  echo "<td width='' bgcolor='' align='' valign=''>";
echo "<td><a href=index.php?iid=$id&tbl=imagea><img src='image.php?iid=$id&tbl=imagea' width=100 height=73 ></a></td>";
$i++;
echo "<td width='' bgcolor='' align='' valign=''>";
echo "<td><a href=index.php?iid=$id&tbl=imagea><img src='image.php?iid=$id&tbl=imagea' width=100 height=73 ></a></td>";
$i++;
echo "<td width='' bgcolor='' align='' valign=''>";
echo "<td><a href=index.php?iid=$id&tbl=imagea><img src='image.php?iid=$id&tbl=imagea' width=100 height=73 ></a></td>";
$i++;

echo "</tr>";

}


i know why this code doesn't work- the $i++ returnes the code to the beginning of the loop. If I do not have something to change "$i" then the same picture will be shown... what you got for me, smat people?
Link to comment
Share on other sites

thanks, don, i think i am on the right track. but just to clarify a dead end... why doesn't the code below work?

while ($l < $num) {

$idi=mysql_result($result,$i++,"image_id");
$idj=mysql_result($result,$i++,"image_id");
$idk=mysql_result($result,$i++,"image_id");
$idl=mysql_result($result,$i++,"image_id");

   
echo "<tr>

<td width='' bgcolor='' align='' valign=''>";
echo "<td><a href=index.php?iid=$idi&tbl=imagea><img src='image.php?iid=$idi&tbl=imagea' width=100 height=73 ></a></td>";

  echo "<td width='' bgcolor='' align='' valign=''>";
echo "<td><a href=index.php?iid=$idj&tbl=imagea><img src='image.php?iid=$idj&tbl=imagea' width=100 height=73 ></a></td>";

echo "<td width='' bgcolor='' align='' valign=''>";
echo "<td><a href=index.php?iid=$idk&tbl=imagea><img src='image.php?iid=$idk&tbl=imagea' width=100 height=73 ></a></td>";

echo "<td width='' bgcolor='' align='' valign=''>";
echo "<td><a href=index.php?iid=$idl&tbl=imagea><img src='image.php?iid=$idl&tbl=imagea' width=100 height=73 ></a></td>";
$i++;

echo "</tr>";

}
Link to comment
Share on other sites

Try this on for size:

[code]
for($i=0;$i<num;$i+4){
  echo "<tr>";
  for($j=0;$j<4;$j++){
    $id=mysql_result($result,$i+$j,"image_id");
    echo "<td width='' bgcolor='' align='' valign=''>";//What's this TD for ?  And there's no matching </td>
    echo "<td><a href=index.php?iid=$id&tbl=imagea><img src='image.php?iid=$id&tbl=imagea' width=100 height=73 ><" . "/a" . "></td>";
  }
  echo "</tr>";
}
[/code]
Link to comment
Share on other sites

okay, so don has helped me out a lot. This code looks like exactly what I need. I copy/pasted it into my page and nothing comes up. i don't think the loop is even starting. doni, where you at?

$count_sql = 'SELECT * FROM imagec';
$result = mysql_query($count_sql);
$num=mysql_numrows($result);

for($i=0;$i<num;$i+4){
  echo "<tr>";

  for($j=0;$j<4;$j++){
   
    $id=mysql_result($result,$i+$j,"image_id");
    echo "<td width='' bgcolor='' align='' valign=''>";
    echo "<a href=index.php?iid=$id&tbl=imagec><img src='image.php?iid=$id&tbl=imagec' width=100 height=73 ><" . "/a" . "></td>";
  }
  echo "</tr>";
}

Link to comment
Share on other sites

[quote author=ksb24930 link=topic=114760.msg467312#msg467312 date=1163434127]
okay, so don has helped me out a lot. This code looks like exactly what I need. I copy/pasted it into my page and nothing comes up. i don't think the loop is even starting. doni, where you at?

$count_sql = 'SELECT * FROM imagec';
$result = mysql_query($count_sql);
$num=mysql_numrows($result);

for($i=0;$i<num;$i+4){
  echo "<tr>";

  for($j=0;$j<4;$j++){
   
    $id=mysql_result($result,$i+$j,"image_id");
    echo "<td width='' bgcolor='' align='' valign=''>";
    echo "<a href=index.php?iid=$id&tbl=imagec><img src='image.php?iid=$id&tbl=imagec' width=100 height=73 ><" . "/a" . "></td>";
  }
  echo "</tr>";
}
[/quote]
I was at work--day job ya know.

just above the start of the for loop:
[code]
echo "<br />Num Value:  " . $num;
[/code]

Edit:  I'm also still curious about that SEEMINGLY extra TD--it doesn't seem to have a purpose and it doesn't seem to have a closing tag.
Link to comment
Share on other sites

welcome back to the cyber world, don (back from the day job). I pasted that code above both of the for loops, and it echoed the number of lines in the page, but still no pics are shown. Is your code sound? I mean is the page not viewing because of me or you? Thank you so freaking much for your help. And the whole TD thing is just something i do to keep myself on my toes.
Link to comment
Share on other sites

This may not be the best... But it woks for me
[code]
<?php
$sql = mysql_query("SELECT * FROM images")or die(mysql_error());
for($r = 0;$r < 1000; $r++){
echo"<tr>\n";
for($c = 0;$c < 5; $c++){
$row = mysql_fetch_array($sql);
if(!$row){
break;
}else{
echo'<td>
<img alt="'.$row[file_name].'" src="thumb/'.$row[file_name].'">
</td>';
}
}
echo'</tr>';
}
?>
[/code]
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.