jaco Posted February 12, 2012 Share Posted February 12, 2012 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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 12, 2012 Share Posted February 12, 2012 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. Quote Link to comment Share on other sites More sharing options...
jaco Posted February 12, 2012 Author Share Posted February 12, 2012 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted February 12, 2012 Share Posted February 12, 2012 I still don't follow. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.