Create array for in_array() function from ExecuteRows

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
dquinlan
User
Posts: 29

Create array for in_array() function from ExecuteRows

Post by dquinlan »

I have some code that works, being

					$neutral_array = array("NA","Average","Somewhat","Neither agree nor disagree","Neither yes or no");
					//
					if (in_array($answer,$neutral_array)) {
						$sentiment="Neutral";
					}

I now want to build this array from a query, like

$neutral_sql = "SELECT Response FROM Sentiments WHERE Sentiment = 'Neutral'";
$neutrals = ExecuteRows($neutral_sql);

How can I process $neutrals into $neutral_array including the string quotes?

This isn't working

    foreach ($neutrals as $neutral) {
        $neutral_array[] = "'" . $neutral["response"] . "'";  
    }
 
if (in_array("NA", $negative_array)) {  // if fails, no Log
	Log("NA exists  "); 
}

arbei
User
Posts: 9390

Post by arbei »

If you use v2024, you may simply use, e.g.

$neutral_array = ExecuteFirstColumn($neutral_sql);

(If you add single quotes like your code above, your "NA" will never be matched because it is not single-quoted.)


Post Reply