Northern Flame Posted January 19, 2008 Share Posted January 19, 2008 I have a file called config.php and I include this file in all my pages. In this file I establish a few variables and functions needed in most pages. I ran into a problem trying to build an array of the online users from my MySQL Database. I want the array to be like this: $config['whos_online'][0] $config['whos_online'][1] etc.... heres the php $config = array( 'title' => 'My Website', 'copy_info' => 'Copyright Information', 'copy_links' => 'Links', 'whos_online' => array( while($nuser = mysql_fetch_array($nuser_q)){ $x => '<a href="/members/profile.php?id='.$nuser['id'].'">'.$nuser['name'].'</a><br>', $x++; } ), 'template' => 'black' ); $nuser_q = mysql_query("SELECT username FROM users WHERE last_active > (NOW() - INTERVAL 5 MINUTE)"); and the error I get is: Parse error: parse error, unexpected T_WHILE, expecting ')' in /path/to/my/website.com/templates/config.php on line 18 Line 18 is where i start the while() statement. Any help will be appreciated Link to comment https://forums.phpfreaks.com/topic/86841-solved-getting-array-from-mysql-db/ Share on other sites More sharing options...
p2grace Posted January 19, 2008 Share Posted January 19, 2008 Try doing it this way: $config = array( 'title' => 'My Website', 'copy_info' => 'Copyright Information', 'copy_links' => 'Links', 'whos_online' => array(), 'template' => 'black' ); while($nuser = mysql_fetch_assoc($nuser_q)){ extract($nuser); $config [0] ['whos_online'] [] = "<a href=\"/members/profile.php?id=$id\">$name</a><br>"; } Link to comment https://forums.phpfreaks.com/topic/86841-solved-getting-array-from-mysql-db/#findComment-443813 Share on other sites More sharing options...
Northern Flame Posted January 19, 2008 Author Share Posted January 19, 2008 oh before i read your message I tried a different way and it seems to be working: while($nuser = mysql_fetch_array($nuser_q)){ $config['whos_online'][$x] = '......'; $x++; } thanks for the suggestion though Link to comment https://forums.phpfreaks.com/topic/86841-solved-getting-array-from-mysql-db/#findComment-443815 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.