JJBlaha Posted June 18, 2007 Share Posted June 18, 2007 I have a mysql code like $sql = "SELECT * FROM table"; $result = (@mysql_query($sql, $dbh) or die(mysql_error())); if($result) { echo "success!"; } This outputs 'success!'. If i then try to count the rows like this $sql = "SELECT * FROM table"; $result = (@mysql_query($sql, $dbh) or die(mysql_error())); $num = mysql_num_rows($result); echo "num is $num"; It outputs 'num is '. I get the same type of thing when i try mysql_fetch_array. Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/ Share on other sites More sharing options...
teng84 Posted June 18, 2007 Share Posted June 18, 2007 echo "num is $num"; try this echo "num is". $num; if $num has a value that should work Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276513 Share on other sites More sharing options...
JJBlaha Posted June 18, 2007 Author Share Posted June 18, 2007 that changes nothing in the output Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276516 Share on other sites More sharing options...
JJBlaha Posted June 18, 2007 Author Share Posted June 18, 2007 also i could insert into the table just fine, so i know it is not having trouble connecting to the database, just counting rows and getting information from rows. Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276518 Share on other sites More sharing options...
teng84 Posted June 18, 2007 Share Posted June 18, 2007 try to remove the @ sign and test if the query has a value or var_dump($result);//see if theres an output say pint_r(mysql_fetch_assoc($result)); Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276519 Share on other sites More sharing options...
JJBlaha Posted June 18, 2007 Author Share Posted June 18, 2007 print_r(@mysql_fetch_assoc($result)); prints nothing if i remove the @ from anything i get a warning, but the output does not change otherwise. Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276522 Share on other sites More sharing options...
teng84 Posted June 18, 2007 Share Posted June 18, 2007 maybe the error is the word table maybe is a reserve word for mysql try to rename it or i say put `table` but stop using table as table name think of other table name instead Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276524 Share on other sites More sharing options...
JJBlaha Posted June 18, 2007 Author Share Posted June 18, 2007 it is not really named table, and it is encased in ``. Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276533 Share on other sites More sharing options...
teng84 Posted June 18, 2007 Share Posted June 18, 2007 first post that you have will surely output success because the errors are then in ur variables so it will return true i dont understand why its not working ok debugging try to query first in your db copy the query and past it to my sql look if theres a result Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276536 Share on other sites More sharing options...
JJBlaha Posted June 18, 2007 Author Share Posted June 18, 2007 ive gone into phpmyadmin, done a query that works, and copied in. it is not the query, it has to be something else. what that is i have no idea. i have tried everything i can think of, nothing helps. this code works on other servers. so it has to be something with my server, but i do not know what. Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276538 Share on other sites More sharing options...
teng84 Posted June 18, 2007 Share Posted June 18, 2007 remove the @ and tell us the warning that might help Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276540 Share on other sites More sharing options...
JJBlaha Posted June 18, 2007 Author Share Posted June 18, 2007 it gives these Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in ... Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in... Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276546 Share on other sites More sharing options...
teng84 Posted June 18, 2007 Share Posted June 18, 2007 it gives these Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in ... Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in... those errors simply telling you that you have an error upon querying and statements are invalid can u send me the real code the causing you trouble Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276548 Share on other sites More sharing options...
JJBlaha Posted June 18, 2007 Author Share Posted June 18, 2007 I dont think you can help me. I tried everything you asked before I came here, the code is sound, it works on other servers. I need to know what setting on my server is causing this problem. Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276554 Share on other sites More sharing options...
trq Posted June 18, 2007 Share Posted June 18, 2007 The code is NOT sound. Those errors indicate your query has failed. Post your actual code and please, remove any error suppression (@). Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276558 Share on other sites More sharing options...
JJBlaha Posted June 18, 2007 Author Share Posted June 18, 2007 no, i added those errors IN, there are no errors. $sql = "SELECT * FROM `random`"; $result = (@mysql_query($sql, $dbh) or die(mysql_error())); print_r(@mysql_fetch_assoc($result)); if($result) { $num = @mysql_num_rows($result); echo "num is" . $num; } prints 'num is'. this means that $result is true, but that $num has a null value. inserting into the table works, but if i try to retrieve data the variables are empty. Quote Link to comment https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-277155 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.