Jump to content

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.

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.