jakebur01 Posted March 20, 2008 Share Posted March 20, 2008 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/97088-trouble-adding-in-additional-loop/ Share on other sites More sharing options...
Psycho Posted March 20, 2008 Share Posted March 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/97088-trouble-adding-in-additional-loop/#findComment-496782 Share on other sites More sharing options...
jakebur01 Posted March 20, 2008 Author Share Posted March 20, 2008 This fixed it: $tmp .= $testingsamicans.' | <b>SSC='.$sscpartnumber.'</b> | '; $tmp .= $testingsamicans2.'<br />'; Thank you, Jake Quote Link to comment https://forums.phpfreaks.com/topic/97088-trouble-adding-in-additional-loop/#findComment-496802 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.