ballouta Posted April 10, 2009 Share Posted April 10, 2009 Hi, I have the table news that contains tens of news: ID news == ==== 3 lablablabalab 5 lababalanaaba i want to seclect randomly 5 news every time a user opens a page. is this possible by a query? please give me a hint thank you Quote Link to comment https://forums.phpfreaks.com/topic/153554-solved-random-rows/ Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 $sql = "SELECT * FROM table ORDER BY RAND() LIMIT 5"; Quote Link to comment https://forums.phpfreaks.com/topic/153554-solved-random-rows/#findComment-806873 Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 Meh. Maq's is better Quote Link to comment https://forums.phpfreaks.com/topic/153554-solved-random-rows/#findComment-806874 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 Meh. Maq's is better Hehe, yeah there's a MySQL function for this, which is faster and is less code EDIT: But props on the creative function EDIT2: Nvm, it went away :'( Quote Link to comment https://forums.phpfreaks.com/topic/153554-solved-random-rows/#findComment-806875 Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 Yeah lol. As someone suggested to me before, I need to make reading the php manual my hobby. There's often a function purposely built to accomplish something I'll spend hours attempting. Quote Link to comment https://forums.phpfreaks.com/topic/153554-solved-random-rows/#findComment-806876 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 Yeah lol. As someone suggested to me before, I need to make reading the php manual my hobby. There's often a function purposely built to accomplish something I'll spend hours attempting. I agree, there's no sense in re-inventing the wheel. You'd be surprised at how many obscure functions there are... Quote Link to comment https://forums.phpfreaks.com/topic/153554-solved-random-rows/#findComment-806883 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.