Jump to content

rand() result but to exclude current id


remybink

Recommended Posts

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";  

 

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.