Jump to content

Array question


realjumper

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.