Jump to content

Archived

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

MDanz

array in loop help

Recommended Posts

i have an array in the loop but it isn't building up with results.  i want it to check if the array exists, if not then create the array. Then in next loop it pushes a new value into the array.  Below isn't working?...

 


while($row=mysql_fetch_assoc($get));
{
$key = $row['keyword'];

$scope= $_SESSION['scope'];


		if (!is_array($scope)) {

		$scopenew = array($key);
		$_SESSION['scope'] = $scopenew;

                } else {

		$scopenew = array_push($scope, $key);
			$_SESSION['scope'] = $scopenew;	

}


}

Share this post


Link to post
Share on other sites

have you tried echoing $scopenew in both of your statements to see what your result are

Share this post


Link to post
Share on other sites

Are you wanting to add all the keywords returned from your query into the $_SESSION['scope'] array? If so all you need to do is

while($row = mysql_fetch_assoc($get));
{
    $_SESSION['scope'][] = $row['keyword'];
}

Share this post


Link to post
Share on other sites

×

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.