tags:

views:

29

answers:

2

I have a boolean field, which seems to be stored as 1 when true.

When trying to grab that field in a while loop, I get the error:

mysql_fetch_array() expects parameter 1 to be resource, boolean given

Should a boolean be stored as "TRUE" instead of "1"?

Otherwise, why would I be getting this error?

edit:

My code:

$sqltotal = mysql_query("SELECT SUM(cost) as total FROM sales where passport = '{$therecord['passport']}' AND {$therecord['paid']} <> 1");
$row = mysql_fetch_array($sqltotal);
+2  A: 

Your error unrelated to how booleans are stored, be it in the database or in PHP.

The first argument to mysql_fetch_array() must be the query you've opened executed with mysql_query; that's what the error says.

Artefacto
OK, I pasted the code I am using, what then should I pass to mysql_fetch_array ?
Jacob
@Jacob See Hammerite's answer – your query has failed.
Artefacto
+2  A: 

There are two things that might have happened here:

  1. You've attempted to carry out a query by using code similar to $resultset = mysql_query(...); but the response from MySQL was an error message, and $resultset contains Boolean FALSE.
  2. You've carried out a query that doesn't return a resultset, such as an INSERT or UPDATE query, and $resultset contains Boolean TRUE which just indicates that the query was successful.

Try the following:

if ( $resultset === false ) {
    echo mysql_error();
} else {
    // whatever you were doing
}
Hammerite
Probably a really dumb question, but what would I use for $resultset? $row is only defined after I would use it, i.e. in the //whatever I was doing part...
Jacob
You edited your question while I was writing my answer. The variable that plays the role of my `$resultset` in your code is `$sqltotal`.
Hammerite