Hello,
I have a problem i cant work out.
I want to select data from table (pictures) where some data = "m" or "f" in another...i will explain:
I have table (pictures) below is a simple structer of it:
ID Pic lastview
2 name2.jpg 38923749
2 name2b.jpg 38923634
3 name3.jpg 38765773
etc
which when someone visits a page it shows the picture that has the smallest time stamp (lastview)
That bit a have figured out
....BUT..... the ID relates the the table 'members' and the gender is either M or F.
I want to be able to get data where LASTVIEW is smallest AND where ID in MEMBERS=only M
This is what i have:
$query = "SELECT * FROM pictures WHERE pictureurl != '' ORDER BY lastviewtimestamp LIMIT 1";
this gets the pic that hasnt been shown for the longest
WHAT I WANT IS TO DO THAT ABOVE BUT ALSO ONLY SELECT FROM 'PICTURES' THAT THE CORRISPONDING ID IN MEMBERS IS MALE.
How do i do this???
i dont want to use a loop to select the pic then check members cos this will take up too much CPU.
$query = "SELECT * FROM pictures WHERE pictureurl != '' ORDER BY lastviewtimestamp LIMIT 1";
$query_result_handle = mysql_query ($query)
or die ('The query failed2!');
$row = mysql_fetch_row ($query_result_handle);
$id = $row[15];
Maybe:
$query = "SELECT * WHERE pictureurl != '' ORDER BY lastviewtimestamp FROM pictures LIMIT 1 AND SELECT * WHERE id = '$id' AND gender='M' FROM members";
$query_result_handle = mysql_query ($query)
or die ('The query failed2!');
$row = mysql_fetch_row ($query_result_handle);