(SELECT id,
fname,
birthday,
pic1 FROM
pro_membersu
where gender=1
order by rand()
limit 2
)
union
(SELECT id,
fname,
birthday,
pic1 FROM
pro_membersu
where gender=2
order by rand()
limit 2
)
also a question or two for you?
are your birthdays in a valid date format? If not why not?
more importantly why do all the calculations on it in php when you can do them directly in mysql?
Code:
select month(birthday)
for instance would give you the month for the birthday
or if you are trying to calculate ages you can do that using date_sub and comparing against current_date().
much easier to get the data and calculations you need directly in the database if you ask me.
I changed as you two said, but it is not working.
$q_fems = "SELECT id,fname,birthday,pic1 FROM pro_membersu WHERE gender = 2 ORDER BY RAND() LIMIT 2";
Please look at this link www.ushomenow.com/vietnam , on the right, sometimes the pictures showed, soemtimes not, and errors.
Well, the query does not return the data I wanted. Based on my understanding, Limit 2 means it returns 2 random pictures, but it returns only one pic.
thanks.
My guess is there is something wrong with the code you are using to display the db results, and/or you are not cycling through all of the results....post your modified code, that will shed light on things for us.
And put it inside PHP tags...you don;t need to attach a script that small.
I don't know if this matters or not -- maybe someone can help me with this one -- but while you're looping thru the results of each query you're adding indexes to previously undefined arrays ($m_array, $f_array, etc). This seems like it's a scope problem, but I'm just guessing. I'm in the habit of declaring EVERYTHING on top, basically because of problems like this. Either do a print_r on those arrays after each query loop, or try just defining each of those arrays at the top of the script.
PHP Code:
$m_array = array();
$f_array = array();
etc
If it still fails after that, echo the output values of the fields your pulling from the db and just make sure that you're getting what you expect there.