me1000 Posted July 10, 2007 Share Posted July 10, 2007 Hi, So I have a table, in it there is a bunch of images that have a field that contains a number for which they are associated with. here is a partial screenshot now I need to get the images from the page, but only if there are images. if there are no images associated with the page defined, then it will not display anything. $inPageID = (is_numeric($_REQUEST['page'])) ? $_REQUEST['page'] : "1"; $numpic = mysql_query("SELECT * FROM VISUALS WHERE ASSO=$inPageID"); $num_pic = mysql_num_rows($numpic); if ($num_pic > "0" ) { echo '<div>'; echo 'it found pics'; echo '</div>'; } trouble is it doesn't work! ??? however if I change the greater than sign if ($num_pic > "0" ) to an equal sign it doesn't work either. so just out of curiosity I changed it to a less than sign, and what do you know, it worked! So since I know it is not returning a negative number is it returning a null set? Can anyone help? Thanks, Quote Link to comment Share on other sites More sharing options...
per1os Posted July 10, 2007 Share Posted July 10, 2007 $inPageID = (is_numeric($_REQUEST['page'])) ? $_REQUEST['page'] : "1"; $numpic = mysql_query("SELECT * FROM VISUALS WHERE ASSO=$inPageID"); $num_pic = mysql_num_rows($numpic); if ($num_pic > 0) { echo '<div>'; echo 'it found pics'; echo '</div>'; } Don't use " " around ints that are not to be taken literally. Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 10, 2007 Share Posted July 10, 2007 Could be because "0" != 0 "0" is a string, not the number 0. Try using if (mysql_num_rows($numpic) > 0) No need to create a varialbe just to test it once. Quote Link to comment Share on other sites More sharing options...
me1000 Posted July 10, 2007 Author Share Posted July 10, 2007 Thank You two, That fixed it! there was also another problem, however it was minor, I think it was just the quotes. thanks again! Quote Link to comment Share on other sites More sharing options...
me1000 Posted July 11, 2007 Author Share Posted July 11, 2007 it seems Im having a similar problem, however with a different part. Why is this so difficult? anyway, $inLetterID = (isset($_REQUEST['letter'])) ? $_REQUEST['letter'] : "A"; echo $inLetterID; This always prints "A" (unless otherwise defined) $sqlquery = "SELECT * FROM INFORMATION WHERE LETTER like $inLetterID"; $num_pages = mysql_num_rows($sqlquery); echo '<br>'.$num_pages.': NUMBER OF PAGES<br>'; (for simplicity sake, i did not include the loop) the above puts this on the screen, : NUMBER OF PAGES no number (the number should return "1") here are some DB details, Table name: INFORMATION Column name: LETTER - (VARCHAR; 1 character ) any ideas? Thanks, Quote Link to comment Share on other sites More sharing options...
anatak Posted July 11, 2007 Share Posted July 11, 2007 here is what I recommend to you first echo your query echo $sqlquery and then copy paste that in mysql client to check if you get something back. second it is really not a good practice to assume that your query will not fail something like $num_pages = mysql_num_rows($sqlquery) OR die(mysql_error); will help you a lot And if you really want to know the number of rows I would use count in the query just some suggestions Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 isset($_REQUEST['letter']) aways a so that is always false check if that is really set Quote Link to comment Share on other sites More sharing options...
tapos Posted July 11, 2007 Share Posted July 11, 2007 isset($_REQUEST['letter']) you can use this empty($_REQUEST['letter']) -- Tapos Pal Quote Link to comment Share on other sites More sharing options...
me1000 Posted July 11, 2007 Author Share Posted July 11, 2007 here is what I recommend to you first echo your query echo $sqlquery and then copy paste that in mysql client to check if you get something back. So i tried it, and got this back "Showing rows 0 - 0 (1 total, Query took 0.0003 sec)" second it is really not a good practice to assume that your query will not fail something like $num_pages = mysql_num_rows($sqlquery) OR die(mysql_error); will help you a lot ok, added that, and I will keep that in mind for future referance, And if you really want to know the number of rows I would use count in the query Really all I care about is making sure there is more than one entry, at this point, I need all the information queried later on I just left all that part out for simplicity sake. isset($_REQUEST['letter']) aways a so that is always false check if that is really set my apologies for not being clear, I meant that if the variable is not defined it comes back as "A" however it defines just fine as any other letter. Thanks for you advise, im guessing it is on the database end since it is not coming back from the mysql client. here is what the row looks like, maybe that is of some help. i am just clueless at this point, Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 11, 2007 Share Posted July 11, 2007 Ok, guys it's real simple: $sqlquery = "SELECT * FROM INFORMATION WHERE LETTER like $inLetterID"; $num_pages = mysql_num_rows($sqlquery); You never ran the query! You are running mysql_num_rows() against a string! $sqlquery = "SELECT * FROM INFORMATION WHERE LETTER like $inLetterID"; $result = mysql_query($sqlquery) or DIE (mysql_error()); $num_pages = mysql_num_rows($result); Quote Link to comment Share on other sites More sharing options...
me1000 Posted July 11, 2007 Author Share Posted July 11, 2007 Woohoo! 1 bug down, since I think making a new topic for this next question would be unnecessary, I am not getting this error when running the script, Unknown column 'A' in 'where clause' not sure why I get this, because it shouldnt be calling for a column 'A', it is calling for column 'LETTER' where the value is either 'A' or 'a' Quote Link to comment Share on other sites More sharing options...
tapos Posted July 11, 2007 Share Posted July 11, 2007 $sqlquery = "SELECT * FROM INFORMATION WHERE LETTER like $inLetterID"; you should use this $sqlquery = "SELECT * FROM INFORMATION WHERE LETTER like '$inLetterID'"; -- Tapos Pal Quote Link to comment Share on other sites More sharing options...
me1000 Posted July 11, 2007 Author Share Posted July 11, 2007 Thank You, I really do appreciate it! Quote Link to comment 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.