Skip to content
Advertisement

How can I get the information from one field in a query to use in another query?

I am still trying to finish fixing my details page and I need one more piece to fix it.

I start with this query.

NOTE:recordID actually comes in from the previous page by clicking an item. Also, name, img, item_code, and type_id are fields in my table not outside sources.

Now, I have created this to determine how to display the details about said item:

To explain what is happening here:

This looks at the item that was clicked on the previous page and finds the information about it. If it has a type_id of 4 or higher, I need it to do the following:

  1. Look at the “length” of the current item.
  2. Select all the items from the master_list that has a type_id of 1, 2, or 3 and a matching length to the first one.
  3. Choose 1 random match.
  4. Output the “name, img, and item_code in the same fashion as the first one.

If the item selected originally has a type_id of less than 4, it just posts the original information. This part works. The part from the second query does not.

I have a feeling I need another $_GET[], but not exactly sure how to go about it. The recordID get was attached to the image used as a link.

Can anyone help me to query this so that I get what I am wanting?

Here is a pic of what I am trying to do to help make more sense:

enter image description here

This was done by manually choosing the item to match and putting them together. I want a random item to display.

Here is what the current code looks like. This is the same thing I get with MiK’s answer:

enter image description here

Advertisement

Answer

I finally managed to fix this issue with a combination of tweaking and the answer from MiK.

Here is the final code I ended up with:

The answer provided by MiK fixed the query, but the results were not showing because I had an array inside the array and had to call the inner array. Also, I had to fix the array name so it wasn’t the same as the query.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement