PDA

View Full Version : Put results from db query into array?


ChrisK
10-24-2005, 04:28 PM
I hope someone can help me out here.
I have a number of db entries containing links to images. One field of the db is a number, and I would like to create an array with the image paths sorted by that number.


This code prints out the images in the correct order but I want them placed in an array so I can put them in later referencing the array:
<?PHP
MYSQL_CONNECT("localhost","USER","PASWORD") or die("Connection Failure to Database");
mysql_select_db("DB") or die("Database not found.");
$query = "SELECT * FROM TABLE ORDER BY RATE DESC" or die("Select error");
$result = mysql_query($query) or die("Error: " . mysql_error());
while ($myrow = mysql_fetch_row($result)) {

echo ("<IMG SRC=\"$myrow[10]\" WIDTH=\"100\" HEIGHT=\"75\">");

}

?>


<?PHP
MYSQL_CONNECT("localhost","USER","PASWORD") or die("Connection Failure to Database");
mysql_select_db("DB") or die("Database not found.");
$query = "SELECT * FROM TABLE ORDER BY RATE DESC" or die("Select error");
$result = mysql_query($query) or die("Error: " . mysql_error());
while ($myrow = mysql_fetch_row($result)) {

Instead of printing the results here I want to put every link in an array HOW? This code doesn't work very well................

$newarray = array();
$newarray["link"] = $myrow[10];

// echo ("<IMG SRC=\"$myrow[10]\" WIDTH=\"100\" HEIGHT=\"75\">");

}

echo ("Number one: <IMG SRC=\"$newarray[link][0]\" WIDTH=\"100\" HEIGHT=\"75\">");
echo ("Number two: <IMG SRC=\"$newarray[link][1]\" WIDTH=\"100\" HEIGHT=\"75\">");

?>

schleppel
10-24-2005, 04:39 PM
This should work:
$newarray['link'][] = $myrow[10];