0

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.

1
Contributor
1
Reply
11
Views
4 Years
Discussion Span
Last Post by garyjohnson
0

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);


?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.