Morrac Posted May 5, 2008 Share Posted May 5, 2008 I am having some problems with a couple of MySQL lines of code on a website that I am working on. $q = "SELECT COUNT(ID) FROM ".$tables['TableNameGoesHere']." WHERE AssocA=".$logObj->ID." AND (AssocB=10 OR AssocB=1)"; $r = mysql_query($q); $ra = mysql_fetch_array($r); The problem I am having is that $r is returning Resource id #17 and $ra is returning just Array (not an array just the work Array). I don't know what the problem could be ... I am completely stumped. Quote Link to comment Share on other sites More sharing options...
dooper3 Posted May 5, 2008 Share Posted May 5, 2008 If you echo an array, it will just give you the word array, try using print_r() instead. You need to extract each row of data from the array using extract() If you show us a bit more code then we might understand the problem better. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 5, 2008 Share Posted May 5, 2008 First, this should be under the PHP forum... Code looks good, but you can't just do an echo/print on $ra. If you do a print_r it will show you the values. <?php $q = "SELECT COUNT(ID) FROM ".$tables['TableNameGoesHere']." WHERE AssocA=".$logObj->ID." AND (AssocB=10 OR AssocB=1)"; $r = mysql_query($q); $ra = mysql_fetch_array($r); //Get the first row (there should only be one row) echo $ra[0]; //Print the first column from that row ?> Quote Link to comment Share on other sites More sharing options...
Morrac Posted May 5, 2008 Author Share Posted May 5, 2008 ok using extract($ra) and print the variable that I used for the extract statement I get 0 Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 5, 2008 Share Posted May 5, 2008 Don't worry about extracting each row, because there will only be one row with a COUNT() in the SELECT. My code above should print out the value fine. If you still aren't getting the results you expect, put an: echo $q; in there to make sure the query looks like you expect it to look 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.