realjumper Posted June 21, 2007 Share Posted June 21, 2007 if I create a query like the one below..... $result = mysql_query("SELECT health_safety2, insurance2, security2 FROM incident_property WHERE id = '$id' && health_safety2 != '' && insurance2 != '' && smt2 != ''") or die(mysql_error()); ...how can I put the results into an array, and then count the array. So for exapmle, I know that (in this instance) 'health_safety2' is not equal to empty and smt2 is also not equal to empty...but 'insurance2' IS empty. In that example I want to put the results into an array and then count the array so that I can echo the result, which will be '2'. Because I'm using fields in this query rather than rows in a field, I can't use $num_rows. Thanks for any help :-) Quote Link to comment https://forums.phpfreaks.com/topic/56497-array-question/ Share on other sites More sharing options...
teng84 Posted June 21, 2007 Share Posted June 21, 2007 $result = mysql_query("SELECT health_safety2, insurance2, security2 FROM incident_property WHERE id = '$id' && health_safety2 != '' && insurance2 != '' && smt2 != ''") or die(mysql_error()); is that working^^^^ $array_value=mysql_fetch_assoc($result ); echo sizeof($array_value); ASTIG!!! :-\ :'( Quote Link to comment https://forums.phpfreaks.com/topic/56497-array-question/#findComment-279031 Share on other sites More sharing options...
realjumper Posted June 21, 2007 Author Share Posted June 21, 2007 Thanks...I imagine that the query is okay, but I can't check until I can get the result!!! Chicken and the egg syndrome!!! I'm trying your suggestion as we speak. Quote Link to comment https://forums.phpfreaks.com/topic/56497-array-question/#findComment-279036 Share on other sites More sharing options...
sanfly Posted June 21, 2007 Share Posted June 21, 2007 In the query you have above, you're saying all three fields should not be empty There are two ways I would do it (assuming im understanding you correctly here); option 1 $result = mysql_query("SELECT health_safety2, insurance2, security2 FROM incident_property WHERE id = '$id' && health_safety2 != '' && insurance2 != '' && smt2 != ''") or die(mysql_error()); $num = mysql_num_rows($result); option 2 $num = mysql_result(mysql_query("SELECT COUNT(*) AS NUM FROM incident_property WHERE id = '$id' && health_safety2 != '' && insurance2 != '' && smt2 != ''"), 0); or something along those lines Quote Link to comment https://forums.phpfreaks.com/topic/56497-array-question/#findComment-279041 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.