Jump to content

code for a null outcome


niche
 Share

Recommended Posts

I get "Fatal error: Function name must be a string in" from this script:

if (strlen($row2('firstname') > 0)    {      $hit = 1;    }

Where $row2('firstname') is a null value because it's from a query that produces zero records.How should I script my if statement to avoid the fatal error when zero records are selected?Thanks,Niche

Link to comment
Share on other sites

First, use [brackets] to access array values.You should already have safeguards that prevent you from assigning values to an array if your query produces no results. Test the return value of your query for false, and then (if it's true) pass it to mysql_num_rows before you do anything else. (I'm assuming you're using mysql.)Aside from that, the way to test an array value before you try to access it is with isset() or empty(), as in:if (isset($row2['firstname'] ) ) {// do something}

Edited by Deirdre's Dad
Link to comment
Share on other sites

Aside from that, the way to test an array value before you try to access it is with isset() or empty(), as in:if (isset($row2['firstname'] ) ) {// do something}
Link to comment
Share on other sites

I didn't know that!Point well taken - " don't be satisfied with the easily digested "how to" guides and online documentation - it's shallow."Justsomeguy's last thread allowed me to answer what was to be my next question by finding is_null().Thanks to Deirdre's Dad, thescientist, and justsomeguy. I'm very grateful for your help.Niche

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...