Reply
How do i build this array dynamically?
Old 01-15-2009, 08:08 AM How do i build this array dynamically?
Skilled Talker

Posts: 62
Trades: 0
Hi,

I would like to build the following array dynamically, getting both the key and value from the database.

PHP Code:
array('http://www.google.com/' => 'Google','http://live.com/' => 'Microsoft Live'); 
Right now i have this:
PHP Code:
$linkstring = array();
while (
$qry mysql_fetch_array($sql)) {
     
$linkstring[] = array('siteaddress' => 'sitename');

Note that siteaddress and sitename should become a variable, but i have made them static just for testing.

The output of the values of the above is however a list of the word 'Array', instead of a list of the word 'sitename'. What am i doing wrong?

thanks!

Matt
killerwhale65 is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 01-15-2009, 08:27 AM Re: How do i build this array dynamically?
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
The output of that should be an array of 'siteaddress'=>'sitename' key/value pairs of however many rows teh query returns.

That should work however. If you populate the variables to put in the array something like...

PHP Code:
$siteAddress $qry['siteaddress'];
$siteName $qry['siteName']; 
Oh wait, you are created a 2 dimenional array when you only want a key/value paired array.

try...
PHP Code:
$linkString[$siteAddress] = $siteName
Incidentally, are you sure you dont want the keys/values the other way around so you can access the address from the site name?

Hope this helps....
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 01-15-2009, 08:33 AM Re: How do i build this array dynamically?
Skilled Talker

Posts: 62
Trades: 0
Wonderfull, thanks, that works fine!
killerwhale65 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How do i build this array dynamically?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.15360 seconds with 13 queries