Jump to content

trouble adding in additional loop


jakebur01

Recommended Posts

Hey I have a loop where I am retrieving my items and quantities for my orders. In the middle of this loop I am trying to select a sub part number from a different table specific to the part number from the order.

 

You will see where I tried to do this with the $resultlinda variable. $tmp is now spitting back 864 for some reason. I am doing something wrong.

 

 $result = mysql_query("SELECT * FROM order_items WHERE orderid = '$coolid'", $db);
echo"<table align=center width=650 border=1>";
    echo"<tr>";

            echo"<td width=160 bordercolor=#0066FF bgcolor=#FF0000><div align=center><span class=style1><strong>Order ID</strong></span></div></td>";
           echo" <td width=160 bordercolor=#0066FF bgcolor=#FF0000><div align=center><span class=style1><strong>Part Number</strong></span></div></td>";
            echo"<td width=160 bordercolor=#0066FF bgcolor=#FF0000><div align=center><span class=style1><strong>Price</strong></span></div></td>";
            echo"<td width=160 bordercolor=#0066FF bgcolor=#FF0000><div align=center><span class=style1><strong>Quanity</strong></span></div></td>";
           
          echo"</tr>";
	  echo"</table>";
	  
	   echo "<TABLE align=center width=650 BORDER=1 CELLSPACING=0 CELLPADDING=5>";

while ($myrow = mysql_fetch_array($result))
{
echo"<tr><TD WIDTH=160 align=center>";
echo$myrow["orderid"];
echo"</td><TD WIDTH=160 align=center>";
echo$myrow["isbn"];
echo"</td><TD WIDTH=160 align=center>";
echo$myrow["item_price"];

echo"</td><TD WIDTH=160 align=center>";
echo$myrow["quantity"];


$testingsamicans = $myrow['isbn'];

$testingsamicans2 = $myrow['quantity'];




$resultlinda = mysql_query("SELECT isbn2 FROM books WHERE isbn = '$testingsamicans'", $db);
while ($myrow1 = mysql_fetch_array($resultlinda))
{

$sscpartnumber = $myrow1["isbn2"];


}

   
$tmp .= $testingsamicans.'  |  '.SSC- $sscpartnumber |'.';
    $tmp .= $testingsamicans2.'<br />';


echo"</td>";

echo"</tr>";

  }
echo "</table>";

Link to comment
https://forums.phpfreaks.com/topic/97088-trouble-adding-in-additional-loop/
Share on other sites

I'm not sure what the specific problem is, but don't do queries within loops. Do a join instead and get all the data you need with one query:

 

SELECT *

FROM order_items
  JOIN isbn2 WHERE order_items.isbn = isbn2.isbn

WHERE order_items.orderid = '$coolid'"

 

Edit: here is at least part of your problem:

$tmp .= $testingsamicans.'  |  '.SSC- $sscpartnumber |'.';

 

The pipe character (|) after $sscpartnumber is NOT within the single quote marks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.