Hi guys, I am in need of a code that can put the values of a column in an array. EG:
I have a database with usernames, and I wanted each username to be stored in an array automatically, so each time the page is viewed it runs the code and adds all the users in an array.
I am trying to use this code for my site
http://www.w3schools.com/Ajax/ajax_source.asp
Scroll to the bottom, where the code is for php. Is it possible to the array like that?

Thanks,
-Toxikr3

EDIT: oh oh! I am getting an idea! Please tell me if I am on the right track, you use a while loop to get the usernames and add them each to the array while incrementing the array number... if that is the right way, will someone help me come up with the code?

Recommended Answers

All 2 Replies

Your php code will be something like this, though the precise query commands may differ:

$query = "your sql here";
$qry_result = mysql_query($query) or die(mysql_error());

$myArray = array();
while($row = mysql_fetch_array($qry_result)){
	$myArray[] = $row['userName'];
}

Airshow

Thank you, I will give that ago
-Toxikr3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.