We help IT Professionals succeed at work.
Get Started

PHP & MSSQL - Displaying new data, based on data from a previous table / query

Bergstr asked
Last Modified: 2013-12-12
Im currently trying to query a table, and with the results from the first table, run a new query on the second table - the way im trying to do it is:

At the top of the page i have the following two queries:

$query1 = mssql_query("
SELECT	 StockCode

$query2 = mssql_query("
SELECT  	 ProductID
WHERE ProductID='$MRPDATA[StockCode]'");

Open in new window

and then further down the page i have the following to display the data:

while($MRPDATA = mssql_fetch_array($query1))
	while($BOM = mssql_fetch_array($query2))

  			echo "<tr>";
  			echo "<td>" . $BOM['ProductID'] . "</td>";
 			echo "<td>" . $BOM['ComponentID'] . "</td>";
 			echo "<td>" . $BOM['PerAssyQty'] . "</td>";
 			echo "</tr>";

Open in new window

The problem i have is that query2 in the first section of code wont work with the '$MRPDATA[StockCode]' included - if i replace that with a static part number it works fine...

Anyone know how i can get the variable to work within the query?

Thanks :)
Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE