Topic: PHP - Assigning a query result to an assoc array (Page 1 of 1) Pages that link to <a href="https://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

posted posted 07-11-2011 17:06

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

posted posted 07-12-2011 09:22

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:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu