pcbytes Posted March 20, 2007 Share Posted March 20, 2007 Hah heres the real issue. This works great for spitting out images to my screen from the database... Lets say I deleted id 20 from the database. When the for loop gets to the 20 it just prints a blank image box on the screen. How do I go about getting it to check to see if the id is still there? And if it doesn't exist not to print it. This is what I tried. <? mysql_connect("localhost","jason","p4ssw0rd"); mysql_select_db("test"); $result = mysql_query("select id from upload"); $id = mysql_result($result,0,"id"); $rows = mysql_num_rows($result); for ($i=$id; $i < $rows; $i++){ if($id){ print "<img src=\"download.php?id=$i\"><br>"; } } Link to comment https://forums.phpfreaks.com/topic/43443-solved-omitting-missing-db-ids/ Share on other sites More sharing options...
redarrow Posted March 20, 2007 Share Posted March 20, 2007 <?php mysql_connect("localhost","jason","p4ssw0rd"); mysql_select_db("test"); $result = mysql_query("select id from upload"); $id = mysql_result($result,0,"id"); $rows = mysql_num_rows($result); for ($i=$id; $i < $rows; $i++){ if($id){ print "<img src=\"download.php?id=$i\"><br>"; } }else{ print "<img src=\"no_pic.jpg"><br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/43443-solved-omitting-missing-db-ids/#findComment-210972 Share on other sites More sharing options...
pcbytes Posted March 20, 2007 Author Share Posted March 20, 2007 I've actually tried that, when $i counts to 20. It still prints the blank image box even though id 20 doesnt exist in the database. also tried this to see if it would verify the id in the database with no luck; <? mysql_connect("localhost","jason","p4ssw0rd"); mysql_select_db("test"); $result = mysql_query("select id from upload"); $id = mysql_result($result,0,"id"); $rows = mysql_num_rows($result); for ($i=$id; $i < $rows; $i++){ if ($var1 = mysql_query("select id from upload where id =$i")){ print "<img src=\"download.php?id=$var1\"><br>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/43443-solved-omitting-missing-db-ids/#findComment-210973 Share on other sites More sharing options...
pcbytes Posted March 20, 2007 Author Share Posted March 20, 2007 I almost have this narrowed down. Changed it to a while loop. Now it displays the correct amount of image boxes. but the image boxes are blank because it is not grabbing the row id in the img src= section. <? mysql_connect("localhost","jason","password"); mysql_select_db("test"); $result = mysql_query("select id from upload"); while($row = mysql_fetch_row($result)){ $var1 = $row['id']; print ("<img src=\"download.php?id=$var1\"><br>"); } ?> Link to comment https://forums.phpfreaks.com/topic/43443-solved-omitting-missing-db-ids/#findComment-210986 Share on other sites More sharing options...
pcbytes Posted March 20, 2007 Author Share Posted March 20, 2007 solved... changed the following line while($row = mysql_fetch_row($result)){ to while($row = mysql_fetch_array($result)){ boom. problem fixed. Link to comment https://forums.phpfreaks.com/topic/43443-solved-omitting-missing-db-ids/#findComment-210991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.