hi, i am trying to display a random product from my database along with its description, price and image. but i am having a little trouble. i can display a random product and its info by directly inputting it into an array, but i can't call it from the database itself WITH the array.
i checked google but i just kept being sent to pages that only have scripts that do as i did below or i get taken to pages that have nothing to do with php at all.
Any help will be appreciated.
Here's the code i'm using:
<?php
$get_pic = "SELECT car_name, LEFT(car_desc, 20), car_image FROM cars";
$get_pic_res = mysql_query($get_pic) or die(mysql_error());
if (mysql_num_rows($get_pic_res) < 1){
$display_desc = "<p><em>No products available!</em></p>";
}
else{
while ($pics = mysql_fetch_array($get_pic_res)){
$pics_name = strtoupper(stripslashes($pics[car_name]));
$pics_desc = stripslashes($pics[car_desc]);
$pics_price = $pics[car_price];
$images = array
(
/*array('file' => $pics_name, // here i tried to pass the variable into the array
'caption' => $pics_desc),*/ // i'm not sure that can be done though
array('file' => 'mazda',
'caption' => 'This is the Mazda 626. A cheap, yet luxurious car.'),
array('file' => 'buick',
'caption' => 'This car is all over the country so you may want
to think of getting another car.'),
array('file' => 'hummer',
'caption' => 'If you have the money fo this car, then you MUST have the money for fuel'),
array('file' => 'xrc',
'caption' => 'This is a toy car, plain and simple!')
);
$i = rand(0, count($images)-1);
$selectedImage = "../images/{$images[$i]['file']}.jpg";
$caption = $images[$i]['caption'];
if (file_exists($selectedImage) && is_readable($selectedImage))
{
$imageSize = getimagesize($selectedImage);
}
}
}
?>