I am trying to make an array which has a random selection of database results in it.
This is what I have so far,

<?php 
    $con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("photos", $con);

$query="SELECT album FROM albumname ORDER BY RAND() LIMIT 9";

$result= mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
    $images[] = $row;   
}

echo $images[2];
mysql_close($con);


?>

I want to have 9 results in the array, When i echo the $images[] with any number it only responds Array. It does not give the results from the database.

I resloved the problem on my own and will post the results just in case someone else needs to use them

<?php 
    $con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("photos", $con);

$query="SELECT album FROM albumname ORDER BY RAND() LIMIT 9";

$result= mysql_query($query) or die(mysql_error());
$i=0;
while($row = mysql_fetch_array($result)){
    $images[$i] = $row[0];
    $i++;   
}

mysql_close($con);


?>
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.