heraldic2 Posted March 30, 2013 Share Posted March 30, 2013 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 30, 2013 Share Posted March 30, 2013 Your post is a little confusing, but if you have an array with 4 variables and you want one of the other three, copy the array, remove the one you know, and use shuffle or any other random function. Quote Link to comment Share on other sites More sharing options...
l0gic Posted March 30, 2013 Share Posted March 30, 2013 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? Quote Link to comment Share on other sites More sharing options...
Solution heraldic2 Posted March 30, 2013 Author Solution Share Posted March 30, 2013 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 Quote Link to comment 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.