Jump to content

Weird mySql problem


JJBlaha

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276536
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276538
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-276548
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/55984-weird-mysql-problem/#findComment-277155
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.