Jump to content

Recommended Posts

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 :-)

Link to comment
https://forums.phpfreaks.com/topic/56497-array-question/
Share on other sites

$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!!! :-\ :-* :'(

Link to comment
https://forums.phpfreaks.com/topic/56497-array-question/#findComment-279031
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/56497-array-question/#findComment-279041
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.