corillo181 Posted May 27, 2006 Share Posted May 27, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/10579--/ Share on other sites More sharing options...
litebearer Posted May 27, 2006 Share Posted May 27, 2006 not fully awake yet, but...a missing $ perhaps?[code]if(!row){[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10579--/#findComment-39441 Share on other sites More sharing options...
corillo181 Posted May 27, 2006 Author Share Posted May 27, 2006 nope that was when a pastel here by mistake.. Quote Link to comment https://forums.phpfreaks.com/topic/10579--/#findComment-39444 Share on other sites More sharing options...
litebearer Posted May 27, 2006 Share Posted May 27, 2006 did you check the value of $row? Quote Link to comment https://forums.phpfreaks.com/topic/10579--/#findComment-39446 Share on other sites More sharing options...
corillo181 Posted May 27, 2006 Author Share Posted May 27, 2006 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.. Quote Link to comment https://forums.phpfreaks.com/topic/10579--/#findComment-39452 Share on other sites More sharing options...
litebearer Posted May 27, 2006 Share Posted May 27, 2006 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... Quote Link to comment https://forums.phpfreaks.com/topic/10579--/#findComment-39459 Share on other sites More sharing options...
poirot Posted May 27, 2006 Share Posted May 27, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/10579--/#findComment-39463 Share on other sites More sharing options...
corillo181 Posted May 28, 2006 Author Share Posted May 28, 2006 right on dude :) Quote Link to comment https://forums.phpfreaks.com/topic/10579--/#findComment-39779 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.