newb Posted July 17, 2006 Share Posted July 17, 2006 [code]<?php require "../config.php"; $id = $_GET["id"]; $sql = "SELECT * FROM `thumbs` WHERE id=$id"; $result = mysql_query($sql); // Build Table while( $row = mysql_fetch_assoc( $result ) ) { $imageshow=$row['id']; if ( $id == "$imageshow") { echo '<br /><br /><a href="#" onclick="window.close()"><img class="displaypic" src="images/full/' . $row['category'] . '/' . $row['id'] . '.jpg"></img></a><br />'; } else { echo "Image ID: $id Doesnt Exist"; } } ?>[/code]thats my code, when i type in, say www.mysite.com/thumbs.php?id=4543535435 it wont say 'image id: 4543535435 doesnt exist' and i know it doesnt exist in the database. Quote Link to comment https://forums.phpfreaks.com/topic/14806-doenst-show-my-else-echo-cmd/ Share on other sites More sharing options...
AndyB Posted July 17, 2006 Share Posted July 17, 2006 Because the query failed, most likely. Use this query:[code]$sql = "SELECT * FROM `thumbs` WHERE id='$id'";[/code]Also change this[code]if ( $id == "$imageshow") {[/code]to this:[code]if ( $id == $imageshow) {[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14806-doenst-show-my-else-echo-cmd/#findComment-59130 Share on other sites More sharing options...
newb Posted July 17, 2006 Author Share Posted July 17, 2006 didnt help Quote Link to comment https://forums.phpfreaks.com/topic/14806-doenst-show-my-else-echo-cmd/#findComment-59132 Share on other sites More sharing options...
hvle Posted July 17, 2006 Share Posted July 17, 2006 try this code newb.[code]<?phprequire "../config.php"; $id = $_GET["id"]; $sql = "SELECT * FROM `thumbs` WHERE id='$id'"; $result = mysql_query($sql); if (mysql_num_rows($result) == 0) { echo "Image ID: $id Doesnt Exist"; } else { while( $row = mysql_fetch_assoc( $result ) ) { echo '<br /><br /><a href="#" onclick="window.close()"><img class="displaypic" src="images/full/' . $row['category'] . '/' . $row['id'] . '.jpg"></img></a><br />'; } }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14806-doenst-show-my-else-echo-cmd/#findComment-59136 Share on other sites More sharing options...
kenrbnsn Posted July 17, 2006 Share Posted July 17, 2006 Do you get any output?You really should be checking to see if you got any records returned before you go into the while loop. If there are no records returned your script will not put output anything. Try something like this:[code]<?php $id = $_GET["id"]; $sql = "SELECT * FROM `thumbs` WHERE id=$id"; $result = mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_error()); if (mysql_num_rows($result) == 0) // if no rows returned then id doesn't exist echo "Image ID: $id Doesnt Exist"; else { // Build Table while($row = mysql_fetch_assoc($result)) echo '<br /><br /><a href="#" onclick="window.close()"><img class="displaypic" src="images/full/' . $row['category'] . '/' . $row['id'] . '.jpg"></img></a><br />'; } ?>[/code]Ken (I see hvle beat me to the same code -- GMTA!) Quote Link to comment https://forums.phpfreaks.com/topic/14806-doenst-show-my-else-echo-cmd/#findComment-59137 Share on other sites More sharing options...
newb Posted July 17, 2006 Author Share Posted July 17, 2006 Ohhhh...yep that worked! Thanks a bunch fellas! Quote Link to comment https://forums.phpfreaks.com/topic/14806-doenst-show-my-else-echo-cmd/#findComment-59184 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.