loshyt Posted February 20, 2011 Share Posted February 20, 2011 here is the database: its a facebook app i want that my sql will choose every time random but considerate in the sex parameter. i mean that if the user is boy i will put it in parameter and boys is num-1 girls-0 and if the user is boy it will run random sql just on the boys and if its girls so random on the girls here what i did: $sql = "SELECT * FROM pcm ORDER BY RAND() LIMIT 1"; $Recordset3 = mysql_query($sql) or die(mysql_error()); $row2 = mysql_fetch_object($Recordset3); print_r($row2); but for some reason i get an error that the database is not selected maybe i didnt select my database right? plz help tnx.... Quote Link to comment https://forums.phpfreaks.com/topic/228309-how-to-run-a-random-sql-that-look-for-one-peremeter/ Share on other sites More sharing options...
.josh Posted February 20, 2011 Share Posted February 20, 2011 select * from pcm where sex='1' order by rand() limit 1 Quote Link to comment https://forums.phpfreaks.com/topic/228309-how-to-run-a-random-sql-that-look-for-one-peremeter/#findComment-1177292 Share on other sites More sharing options...
.josh Posted February 20, 2011 Share Posted February 20, 2011 but for some reason i get an error that the database is not selected maybe i didnt select my database right? please help tnx.... okay prev post was the query...that error sounds like you aren't selecting a db when you make a connection...in your code, somewhere before the query, after you use mysql_connect() to connect to connect to mysql, you should be using mysql_select_db to select which db your table is in Quote Link to comment https://forums.phpfreaks.com/topic/228309-how-to-run-a-random-sql-that-look-for-one-peremeter/#findComment-1177294 Share on other sites More sharing options...
loshyt Posted February 22, 2011 Author Share Posted February 22, 2011 many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/228309-how-to-run-a-random-sql-that-look-for-one-peremeter/#findComment-1178143 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.