Jump to content


Photo

Doenst show my else echo cmd


  • Please log in to reply
5 replies to this topic

#1 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 17 July 2006 - 01:20 AM

<?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";
	     }					
	} 
?>

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.

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 17 July 2006 - 01:31 AM

Because the query failed, most likely. Use this query:

$sql = "SELECT * FROM `thumbs` WHERE id='$id'";

Also change this
if ( $id == "$imageshow") {

to this:
if ( $id == $imageshow) {

Legend has it that reading the manual never killed anyone.
My site

#3 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 17 July 2006 - 01:56 AM

didnt help

#4 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 17 July 2006 - 02:34 AM

try this code newb.

<?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 />';
        }
    }
?>

Life's too short for arguing.

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 July 2006 - 02:34 AM

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:
<?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 />';
       } 
?>

Ken (I see hvle beat me to the same code -- GMTA!)

#6 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 17 July 2006 - 05:19 AM

Ohhhh...yep that worked! Thanks a bunch fellas!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users