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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.