Forum Moderators: coopster

Message Too Old, No Replies

truncate table works, but i still get numrows error.

         

nelsonm

5:59 pm on Nov 21, 2010 (gmt 0)

10+ Year Member



Hi all,

I checked database table, and the table is being truncated. But i'm still getting the following error:

Warning: mysql_numrows() expects parameter 1 to be resource


when i execute mysql_numrows($Result) in the php script below:

$sql = "TRUNCATE TABLE distance";
$Result = mysql_query($sql, $conn) or die("<br>** Unable to query distance database table <b>".mysql_error()."</b><br>$sql");
$Rows = mysql_num_rows($Result);

if (!$Result){
echo "<br>** distance table base truncation failed, [$Result] [$Rows].";
exit;
}

nelsonm

10:18 pm on Nov 21, 2010 (gmt 0)

10+ Year Member



btw...

The database contains three tables. I select from the first two tables and get the number of rows selected by using the mysql_num_rows() function without errors. The distance table is the only table i am inserting into.

1. I'm guessing i'm using the wrong function to get the number of rows inserted.
2. I'm guessing that TRUNCATE or INSERT, $Result does not return a resource - just TRUE or FALSE?

enigma1

11:15 pm on Nov 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The function mysql_num_rows is valid for select or show. Try using the mysql_affected_rows instead.

nelsonm

6:34 am on Nov 23, 2010 (gmt 0)

10+ Year Member



it did not work either. However by issuing a "select * from" then i was able to get msql_num_rows to work.

enigma1

8:24 am on Nov 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



how about this code?


$sql = "delete from distance";
$Result = mysql_query($sql, $conn) or die("<br>** Unable to query distance database table <b>".mysql_error()."</b><br>$sql");
$Rows = mysql_affected_rows($conn);

if (!$Result){
echo "<br>** distance table base truncation failed, [$Result] [$Rows].";
exit;
}

nelsonm

3:02 pm on Nov 23, 2010 (gmt 0)

10+ Year Member



that works, thanks.

The problem was that i was testing $Results in mysql_affected_rows() instead of $conn.