Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mysql Results in an array

Status
Not open for further replies.

egmweb

Programmer
Mar 19, 2004
147
EU
Hello Guys.

I'm trying to make an script to makes the results of an mysql query into an array, for example:

$mysql = mysql_query("SELECT gallery.name FROM gallery");
while ($row = mysql_fetch_row($mysql)){
$g = $row[0];
echo $g.' ';
}
The results will be: gal1 gal2
We need this values be stored in differents variables, like this:
$1 = gal1;
$2 = gal2; etc.

Would you please help me with this script?

Thanks you.
 
Change:

Code:
$mysql = mysql_query("SELECT gallery.name FROM gallery");
while ($row = mysql_fetch_row($mysql)){
    $g = $row[0];
        echo $g.' '; 
}

to

Code:
$g = array();
$mysql = mysql_query("SELECT gallery.name FROM gallery");
while ($row = mysql_fetch_row($mysql)){
    $g[] = $row[0];
}
print_r ($g);

At the end of the loop, the elements of the array $g will contain the values from the database.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Thanks you Very much sleipnir214, it works

Regards.
 
How can you sort those values by 2 different things. Say in g I had date and title i wanted to sort by how can i do that
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top