ksb24930 Posted November 13, 2006 Share Posted November 13, 2006 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? Quote Link to comment Share on other sites More sharing options...
ksb24930 Posted November 13, 2006 Author Share Posted November 13, 2006 is there a way to add more than just one (++) to the variable $i at a time? Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 13, 2006 Share Posted November 13, 2006 $i += 5;This will add 5 to the $i variable and set $i to the result. Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 13, 2006 Share Posted November 13, 2006 Also, in looking at your original post above, I gotta wonder, are you INTENDING to show three links ALL the same and ALL the same image? Quote Link to comment Share on other sites More sharing options...
ksb24930 Posted November 13, 2006 Author Share Posted November 13, 2006 no, that is exactly what i am trying to avoid! I want the images to be shown four across. so if there were 12 images in the table named 1-12, the page would look like this:1 2 3 45 6 7 89 10 11 12 Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 13, 2006 Share Posted November 13, 2006 Then you need to do the query before each item. Otherwise the variables aren't changing. Quote Link to comment Share on other sites More sharing options...
ksb24930 Posted November 13, 2006 Author Share Posted November 13, 2006 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>";} Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 13, 2006 Share Posted November 13, 2006 is that copy/pasted?the while loop checks $l (lower case L) not $i. Dunno if that's your problem, but....... Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 13, 2006 Share Posted November 13, 2006 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] Quote Link to comment Share on other sites More sharing options...
ksb24930 Posted November 13, 2006 Author Share Posted November 13, 2006 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 Link to comment Share on other sites More sharing options...
ksb24930 Posted November 13, 2006 Author Share Posted November 13, 2006 maybe i could substitute a while loop for the first for loop...? Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 14, 2006 Share Posted November 14, 2006 [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. Quote Link to comment Share on other sites More sharing options...
ksb24930 Posted November 14, 2006 Author Share Posted November 14, 2006 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. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 14, 2006 Share Posted November 14, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.