Jump to content

Random item that is not itself


heraldic2
Go to solution Solved by heraldic2,

Recommended Posts

Greetings all,

 

I have four products that can be either version 1 or version 2.  I will never know before hand which version they are.  It is entered into the database by an intranet page.

 

I am trying to take these 4 products, sort them by their version and then I need to take a product and pair it with another product of the same version, but not itself.

 

EXAMPLE

product 1 v1

product 2 v2

product 3 v1

product 4 v1

 

array(product 1, product 3, product 4)

product 1 needs a random pairing from the array that is not itself.

 

 

The way the company has the database setup this can not be done in the query.

table has product1_name, product1_version, product2_name, product2_version and so on.

 

So I pull each product name and product version out of the database and put them in variables

Product1=product1_name

product1version=product1_version

 

 

I have hit a wall though on how best to go about this.  other than re-doing the database table can anyone lend a hand?

 

Thanks for your time.

Link to comment
Share on other sites

I think I understand, and I'd try using (or loading the database results into) a multidimensional array.

 

Thinking:

array(
  array( Product => "Product 1", 
         Version => 1
  ),
  array( Product => "Product 2",
         Version => 2
  ),
  array( Product => "Product 3",
         Version => 1
  ),
  array( Product => "Product 4",
         Version => 1
  )
);

 

 

And looping through the array using conditionals to obtain desired results?

 

This would allow you to pick out certain products, or certain versions.

 

However I may not actually understand your post, as, if you had the the products and the versions listed in your database, then aren't you already set-up to do what you want?

Link to comment
Share on other sites

  • Solution

First let me say sorry for the confusing post.  The setup is confusing and is very difficult to put into words.

 

However thank you for the answers as combined they gave me the perfect answer.  Put the products into a multidimensional array and then remove the current product and pull out a random product afterwards.

 

As always you folks rock!

 

Thank you very much

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.