Jump to content


Photo

:|????


  • Please log in to reply
7 replies to this topic

#1 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 27 May 2006 - 01:57 PM


why is this not working.. if there is a title it show it but if the tittle is empty it does not show the no title
<?php
$getdes=mysql_query("SELECT descrive FROM tra_photo WHERE photo_id=$foto_id")or die(mysql_error());
$row=mysql_num_rows($getdes);
$fet=mysql_fetch_array($getdes);
if(!row){
echo "Not Title";
}else{
echo $fet['descrive'];

}
?>


#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 27 May 2006 - 02:00 PM

not fully awake yet, but...

a missing $ perhaps?

if(!row){

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 27 May 2006 - 02:04 PM

nope that was when a pastel here by mistake..

#4 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 27 May 2006 - 02:12 PM

did you check the value of $row?

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#5 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 27 May 2006 - 02:40 PM

mm that is the point of the if statement, if there is something is going to echo that something if there is nothing is going to say no tittle..

when there is something it works and echos what ever is in the query, but when ther eis nothing it does not show the no tittle..

#6 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 27 May 2006 - 03:03 PM

Don't get me wrong, i am NOT by any stretch a guru; but my understanding of

$row=mysql_num_rows($getdes);

is that it counts the number of rows that are returned. Thus even if the number is 0, it does have a value. in other words it is NOT a TRUE/FALSE variable. IF that is correct then (and again my understanding may be wrong), this

if(!row){

says "Is there are value in $row". Oviously if I am correct so far in my thinking, the answer is "Yes, the value is 0". Moving along, since the answer is "yes" the script says "display the row contents"; however since there is NO row that met the conditions it will display nothing.


I may be all wet but remember I am simply an old fart learning as I go and totally sefl taught.

Lite...



all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#7 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 27 May 2006 - 03:19 PM

I took the liberty to rewrite it:
<?php

$getdes = mysql_query("SELECT descrive FROM tra_photo WHERE photo_id='$foto_id' LIMIT 1")or die(mysql_error());

if (mysql_num_rows($getdes) == 0) {
   echo "Invalid Id";
} else {
   $fet = mysql_fetch_array($getdes);
   $title = empty($fet['descrive']) ? 'No Title' : $fet['descrive'];
}

echo '<title>' . $title . '</title>';

?>
I added singlequotes (='$foto_id') because MySQL won't work without them here. Also LIMIT 1 to ensure it returns 1 row only.

And, I made it fetch the results only if there is a row. $title is determined by the ternary operator.
~ D Kuang

#8 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 28 May 2006 - 07:18 PM

right on dude :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users