Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on what you mean.</p> <p><a href="http://ca2.php.net/mysql_result" rel="nofollow noreferrer">mysql_result</a> returns <code>FALSE</code> on failure, which would happen if you specified an invalid (row,field). To check for this you'd want to do use the identicality operator <code>===</code>, which checks both value and type. The equality operator <code>==</code>, the <code>empty()</code> function, and the conditional evaluation of an if statement all check the value but not the type.</p> <p>This means that using one of those methods there's no difference between various values that all equate to <code>Boolean FALSE</code>, like empty strings, empty arrays, the string <code>'0'</code>, and the value <code>NULL</code>.</p> <p>So if you want to be really thorough about it you could do something like the following:</p> <pre><code>if ($description === FALSE) { throw new Exception("The row $i was out of range in query $query."); } else if ($description === NULL) { // assuming that the description field has a default value of NULL // * this one I'm not sure about.. the documentation for mysql_result claims // that it returns a string, so this may never happen. // It's left as an exercise for the reader. throw new Exception("Uninitialized value in result row $i of db query $query"); } else if ($description === '') { echo "No description available"; } else { echo $description; } </code></pre> <p>Since <code>empty()</code> returns <code>true</code> under a similar set of conditions to an equality (<code>==</code>) with <code>FALSE</code>, this more strict in your type checking would be especially important in cases where the result might actually be <code>"0"</code>. </p> <p>Apparently I'm not allowed to post more than one hyperlink, so I wasn't able to link to the documentation for comparison operators ("<a href="http://php.net/manual/en/language.operators.comparison.php" rel="nofollow noreferrer">http://php.net/manual/en/language.operators.comparison.php</a>") or the empty function ("<a href="http://php.net/empty" rel="nofollow noreferrer">http://php.net/empty</a>"). Fortunately their security is relatively lax. Mwuh Hah!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload