Jump to content

:|????


corillo181

Recommended Posts


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
[code]
<?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'];

}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/10579--/
Share on other sites

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

[code]$row=mysql_num_rows($getdes);[/code]

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

[code]if(!row){[/code]

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...


Link to comment
https://forums.phpfreaks.com/topic/10579--/#findComment-39459
Share on other sites

I took the liberty to rewrite it:
[code]<?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>';

?>[/code]
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.
Link to comment
https://forums.phpfreaks.com/topic/10579--/#findComment-39463
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.