nick: pass: email:
nick1 testpass some@thing
nick2 test none
nick3 hello test@domain.com
....... ....... ..........................
and so on
I want to return an array with all the nicks, but i've got no idea on hwo to do it. i've looked at the MySQL functions on php.net, but I can't find a/the function that does this.....
Edit: is this only possible by using ForEaach, or While?
Last edited by vigge89 on Thu Jan 15, 2004 2:44 pm, edited 1 time in total.
<?php
// intialise as an array
$all_the_nicks = array();
while($result = mysql_fetch_array($query))
{
$all_the_nicks[] = $result['nick'];
}
?>
Check out the manual for the mysql_fetch functions. Often they are pretty much interchangable.
Just in case you're not sure what $all_the_nicks[] means, this is a way of assigning new elements to an array. The (numerical) key is set +1 the last highest key.
You should always initialise a variable as an array before you start trying to add elements to it.
Last edited by McGruff on Wed Aug 10, 2005 12:00 am, edited 1 time in total.
Ooops I just noticed you've got 200-odd posts.. presumably you know how to loop through a db query.
In a sense a "SELECT nick FROM table" result resource is itself an array of nicks (which you could maybe just chuck around where it's needed) but, to create a php array, you'll have to do the standard loop & assign element thang.
ok, so there wasn't any MySQL function that did the job for me
Just in case you're not sure what $all_the_nicks[] means, this is a way of assigning new elements to an array. The (numerical) key is set +1 the last highest key.