Jump to content

Recommended Posts

[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.
Link to comment
https://forums.phpfreaks.com/topic/14806-doenst-show-my-else-echo-cmd/
Share on other sites

try this code newb.

[code]
<?php
require "../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]
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!)
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.