winnard2008
08-12-2008, 03:35 PM
Hi Guys,
I need to create a random image to be generated on a home page I am doing.
Basically I need to put three random images in three seperate boxes on the homepage.
These images need to be based on a category id.
1. Bi-Folding doors
2. Windows and Doors
3. Conservatories.
The image (image1) is in a table called portfolio, the cat_id is in the portfolio table and linked with portfolio_cat table.
I need the code for the following
get image1 from portfolio table where its cat_id is = 1,2 or 3 and limit that to just one image to view.
I have this piece of code which generates random images I just don't know how to change it to do what I need.
Here is the code
<?PHP
mysql_select_db("$database", $dbh);
$sql = "SELECT * FROM portfolio ORDER BY ????????? RAND() LIMIT 1";
$query = mysql_query($sql, $dbh) or die ("Error in query: $sql" . mysql_error());
//Now we loop through each record returned.
while ($row = mysql_fetch_array($query))
{
//get values from database
$id = $row['??????']; //usually database record id
//now generate using above values - note html <option>
echo $row['??????'];
}//end of loop
?>
Can anybody help with this?
I have a feeling the echo statement might need to change also so if anybody could do the code for that then that would be great.
Cheers
Dan
I need to create a random image to be generated on a home page I am doing.
Basically I need to put three random images in three seperate boxes on the homepage.
These images need to be based on a category id.
1. Bi-Folding doors
2. Windows and Doors
3. Conservatories.
The image (image1) is in a table called portfolio, the cat_id is in the portfolio table and linked with portfolio_cat table.
I need the code for the following
get image1 from portfolio table where its cat_id is = 1,2 or 3 and limit that to just one image to view.
I have this piece of code which generates random images I just don't know how to change it to do what I need.
Here is the code
<?PHP
mysql_select_db("$database", $dbh);
$sql = "SELECT * FROM portfolio ORDER BY ????????? RAND() LIMIT 1";
$query = mysql_query($sql, $dbh) or die ("Error in query: $sql" . mysql_error());
//Now we loop through each record returned.
while ($row = mysql_fetch_array($query))
{
//get values from database
$id = $row['??????']; //usually database record id
//now generate using above values - note html <option>
echo $row['??????'];
}//end of loop
?>
Can anybody help with this?
I have a feeling the echo statement might need to change also so if anybody could do the code for that then that would be great.
Cheers
Dan