Jump to content

Check if all values in array = accept


savagenoob

Recommended Posts

After doing a mysql_query and pulling data into an array like:

 

$polquery  = mysql_query("SELECT * FROM disclosures WHERE transid = '$transid'");
while($something = mysql_fetch_array($polquery){
$status = $something['complete'];
}

I need to cycle through the array $status to see if all values = "accept", I'm not sure how to do this... or just forgot.

Maybe just do a while($status == "accept")?

Link to comment
https://forums.phpfreaks.com/topic/216534-check-if-all-values-in-array-accept/
Share on other sites

 

Why not just do it in the while() loop?

 

<?php
$polquery  = mysql_query("SELECT * FROM disclosures WHERE transid = '$transid'");
while($something = mysql_fetch_array($polquery) ) {
   if( $something['complete'] == 'accept' ) {
      //Do something
   } else {
      // Do something else
   }
}
?>

Right, and if any value in the while loop doesn't == 'accept' it goes to the else{ }, where you can kill the script, or anything else you'd like to do to handle it.

 

Unless I'm missing something, this is what you've described. If I've misunderstood you, let me know.

How about this then, this should work just fine for what you're describing.

 

<?php
$all_accepted = TRUE;
$polquery  = mysql_query("SELECT * FROM disclosures WHERE transid = '$transid'");
while($something = mysql_fetch_array($polquery) ) {
   if( $something['complete'] != 'accept' ) {
   	$all_accepted = FALSE;
   }
}

if( $all_accepted === TRUE ) {
// display link
echo '<a href="link_to_next_page.php">Click to proceed</a>';
}
?>

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.