Jump to content

null values and mysqlfetcharray


jaco

Recommended Posts

Hi, this is a question that may have been asked but a search does not reveal anything.

 

I am trying to identify a null result from a select and mysqlfetcharray command, As we know mysql ignores null result from a SELECT command.

 

Here is the code:

 

    $query = "SELECT * FROM chords_".$scale_menu."_2nd_inv WHERE int_number = $i AND sort_name = '$variation_menu'";

    //run the query on the server

    if (!($result = @ mysql_query ($query, $connection)))

    showerror();

 

    $row = mysql_fetch_array($result);

    //required to test for null value

    $query2 = "SELECT * FROM chords_".$scale_menu."_2nd_inv WHERE int_number = $i AND sort_name = '$variation_menu' IS NULL";

    //run the query on the server

    if (!($result2 = @ mysql_query ($query2, $connection)))

    showerror();

 

    $row2 = mysql_fetch_array($result2);

    echo $row;

 

    if (!isset($row2['file_name']))

        {

        echo "there is no 2nd inversion for this chord";

        break;

        }

 

    // do something else

 

    }  //end of while

 

    }

 

 

There are 2 SELECTS in a row, the second one tries to identify if the result is NULL and break out of the loop. But it doesn't work. Any ideas?

 

 

Thanks,

 

Jacques

Link to comment
Share on other sites

As we know mysql ignores null result from a SELECT command

 

What do you mean by that?

 

How about a sample of the actual data, the result you're trying to get, and the result you're currently getting? Your queries and your question don't make much sense, I'm afraid.

Link to comment
Share on other sites

Right, I was trying to make it simple, but you're right. The data is file names that represent chords (see www.chordsandguitar.com). In the new version I am making which is still in test I am adding inversions which is another form of guitar chord based on a master chord. A chord can have 1, 2 or 3 inversions but sometimes there is no 2nd or 3rd inversion. When there is no inversion, it means there are no values in the db, so the chord name that I am looking for just does not exist. So in fact it is a null value but the mysqlfetcharray won't return a null value. I want to be able to skip the display of chords when the inversion does not exist therefore I need to detect a NULL value return which is my problem.

 

I hope this is more clear.

 

Jacques

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.