Topic: PHP - Assigning a query result to an assoc array (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=32306" title="Pages that link to Topic: PHP - Assigning a query result to an assoc array (Page 1 of 1)" rel="nofollow" >Topic: PHP - Assigning a query result to an assoc array <span class="small">(Page 1 of 1)</span>\

 
PixelMamma
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Jul 2011

IP logged posted posted 07-11-2011 17:06 Edit Quote

Only the last record gets assigned to the array. I dont understand why.

code:
$resulturl=mysql_query("SELECT title, friendly_url_path, id
FROM pmd_v2_locations
WHERE level =4
AND friendly_url_path LIKE 'United-States/alabama%'
ORDER BY title") or die(mysql_error());

$arrayurl=array();


while($rowl = mysql_fetch_array($resulturl))  
{
		
		$split = ( list ($Country, $State, $County, $City) = split("/", $rowl[friendly_url_path]) );
		
		$arrayurl['$Country1'] = strtoupper($Country);
		
		$arrayurl['$State1'] = strtoupper($State);
		
		$arrayurl['$County1'] = strtoupper($County);
		
		$arrayurl['$City1'] = strtoupper($City);
		
		$arrayurl['$rowlid1'] = $rowl[id];
		

}

foreach ($arrayurl as $key => $value)
{
	
	echo $key.' - '. $value;
	
}



edit TP: stuck in some code tags.

(Edited by Tyberius Prime on 07-12-2011 09:20)

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 07-12-2011 09:22 Edit Quote

That would be because you have just one level associative arrays.
What you (probably) want is to create a new array in the loop,
and append that with $arrayurl[] = $my_new_array.

So long,

->Tyberius Prime



Post Reply
 
Your User Name:
Your Password:
Login Options: Remember Me On This Computer
 
Your Text:
Loading...
Options: Show Signature
Enable Slimies
Enable Linkwords

« BackwardsOnwards »

Show Forum Drop Down Menu