i have a vehicle inventory system ,that you guys helped me fix, that I want to be able to pull 2 random vehicles from it to display on a sidebar to a website.
Basically I want it to just grab 2 random cars (Image, Year, Make, Model, and Price) and place them in a vertical line for dynamic sidebar data. I was wanting the images to be grabbed randomly every time the page is refreshed or every time it gets visited but I’m having a little trouble with this code as well.
Another thing is that the image in the database is only an image location pointer, pointing to folder on the web server that’s back one directory (…/admin/$imagevariable).
[php]<?php
$dbhost=“localhost”;
$dbname=“auto”;
$dbuser=“root”;
$dbpass="";
mysql_connect("$dbhost","$dbuser","$dbpass") or die("Failed to connect to mysql");
mysql_select_db("$dbname") or die("Failed to open database");
$sql="select * from veh";
$res=mysql_query($sql) or die("Cant execute query");
$num_rows=mysql_num_rows($res);
$row=rand(1,$num_rows);
$sql2="select * from veh where id > 1" . $row;
$result=mysql_query($sql2);
while($data=mysql_fetch_array($result))
{
echo '<img src="../admin/ $data[11]">';
echo "<p><b><u>" . "Year: </b></u>" . $data[1] .
"<p><b><u>" . "Make: </b></u>" . $data[2] .
"<p><b><u>" . "Model: </b></u>" . $data[3] .
"<p><b><u>" . "Price: </b></u>" . $data[7]
;
}
mysql_close();
?>[/php]
So far this code will grab the text data, but not the image itself only the image path, and it also only repeats the same record over and over.
Any help would be greatly appreciated in helping me figure this little piece of code out