Jump to content

Sorting list/array


phpnewone

Recommended Posts

Hello.  I am just trying to sort an array alphabetically.  Here's the code I'm using:

 

function GetAssocCharities($registrationNo)
{
	$db = ConnectionString::ConnectTo_www_ago_mo_gov_data();
	$sqlstring = "SELECT * FROM charityPartners where RegistrationNo LIKE '$registrationNo' ORDER BY Name";


	$results = @mysql_query($sqlstring);

	$org = null;


	while ($resultArray = mysql_fetch_array($results))
	{

		$temp = new Registrants($resultArray['ARegNoFormatted'], $resultArray);

		$org[] = $temp; 
	}

	return asort($org);

}

 

When I try to loop through the array using a foreach loop, I get an error that Invalid argument supplied for foreach().

 

Here's my foreach loop:

$lstCharities = OrgQueries::GetAssocCharities($registrant->RegNoFormatted);

foreach($lstCharities as $c)
		{

//dom something here
}

 

I'm sure its something with not understanding list v array or something or that nature, but I'm not having much luck figuring it out with google.

 

Thanks!

Link to comment
Share on other sites

The sorting functions return true or false, depending on success or failure. So instead of returning an array you are now either returning true or false, hence why it is throwing the error at you. You simply call asort() then return the variable normally.

 

asort($org);
return $org;

 

Always make sure you check the manual my friend. :)

Link to comment
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.