remybink Posted July 28, 2011 Share Posted July 28, 2011 On the side menu I would like to use my rand() function, but the side menu is just extra products, the main part of the page has a product which i do not want in the side menu rand() function so, does the $_GET['id'] come to play here too? also, i am calling "select..... and mysql_query twice on this page, once for main part of page and second for side menu, i dont know if it can be merged, but for my sanity i prefer to keep them separate. plus it allows me to add this menu in other pages easier. I would like to try it myself first if someone can give me a hint -- $records = "SELECT * FROM (items) ORDER BY RAND() LIMIT 3"; Quote Link to comment https://forums.phpfreaks.com/topic/243128-rand-result-but-to-exclude-current-id/ Share on other sites More sharing options...
teynon Posted July 28, 2011 Share Posted July 28, 2011 Put a WHERE to prevent the main page item from showing up on the side menu. By the way, order by rand() is going to be really slow if your dB gets big. $records = "SELECT * FROM (items) WHERE ID != '{$_GET['id']}' ORDER BY RAND() LIMIT 3"; Quote Link to comment https://forums.phpfreaks.com/topic/243128-rand-result-but-to-exclude-current-id/#findComment-1248754 Share on other sites More sharing options...
remybink Posted July 28, 2011 Author Share Posted July 28, 2011 Thank you very much. The pointer on speed of rand() is appreciated. This db will be just for my very small business. I won't have more than 100 products between all categories. But it's great advice while I learn PHP/MySQL I wish I was strong in it like I am in CSS -- thanks again Quote Link to comment https://forums.phpfreaks.com/topic/243128-rand-result-but-to-exclude-current-id/#findComment-1248762 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.