rayder_psca Posted August 26, 2007 Share Posted August 26, 2007 Hey guys, just wondering if someone could help me out with a small problem. I need some help trying to work out how i can select a random product from my database. My initial thoughts figured it'd be easy, i'd just do a row count and do a random number between 1 and row count and display the product whose product id corrosponds with the random number but i ran across a problem with that. When you delete a product, the product id for that particular product is no longer used so i'd end up with mysql access errors if i did that. So if anyone could help me out i'd be very greatful. Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/66746-solved-picking-random-data-using-mysql/ Share on other sites More sharing options...
thefollower Posted August 26, 2007 Share Posted August 26, 2007 find all product ID's put them in an array then just do a rand over the array? use a while loop to create the array..that be my method, but some one prob has a better method than this here. Quote Link to comment https://forums.phpfreaks.com/topic/66746-solved-picking-random-data-using-mysql/#findComment-334475 Share on other sites More sharing options...
pranav_kavi Posted August 26, 2007 Share Posted August 26, 2007 I think this query wud be useful... SELECT * FROM tbl_name ORDER BY RAND(); you can retrieve rows in random order... Quote Link to comment https://forums.phpfreaks.com/topic/66746-solved-picking-random-data-using-mysql/#findComment-334479 Share on other sites More sharing options...
rayder_psca Posted August 26, 2007 Author Share Posted August 26, 2007 Awesome. Those are a great help guys. I particularly like the second reply. I didn't even know that existed lol. Once again, Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/66746-solved-picking-random-data-using-mysql/#findComment-334481 Share on other sites More sharing options...
pranav_kavi Posted August 26, 2007 Share Posted August 26, 2007 pls modify the post status to 'SOLVED' Quote Link to comment https://forums.phpfreaks.com/topic/66746-solved-picking-random-data-using-mysql/#findComment-334484 Share on other sites More sharing options...
rayder_psca Posted August 26, 2007 Author Share Posted August 26, 2007 Oh ok. Sorry about that. Quote Link to comment https://forums.phpfreaks.com/topic/66746-solved-picking-random-data-using-mysql/#findComment-334725 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.