Jump to content

[SOLVED] Getting Array From MySQL DB


Northern Flame

Recommended Posts

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

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>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.