Forum Moderators: coopster

Message Too Old, No Replies

Order By Question

         

jeffgman

6:43 pm on Aug 18, 2004 (gmt 0)

10+ Year Member



I have a problem with a SELECT statement for a MySQL database. I have two databases, one has all of the items for a particular order. The other database has the detail for each of those items. Here is my logic for pulling the data out of each database:

$detailqry6 = "SELECT * FROM whse_order_detail WHERE order_no = '".$order_no."' AND order_qty!= 0";

$result6=mysql_query($detailqry6, $conn);

while ($row=mysql_fetch_array($result6, $conn)) {
$order_no2=$row["order_no"];
$id_no=$row["id_no"];
$sku=$row["sku"];
$order_qty2=$row["order_qty"];
$order_date=$row["order_date"];
$store2=$row["store"];

$detailqry7 = "SELECT * FROM whse_order_items WHERE id_no = '".$id_no."' ORDER BY location";

$result7=mysql_query($detailqry7, $conn);

while ($row=mysql_fetch_array($result7, $conn)) {
$id_no=$row["id_no"];
$sku=$row["sku"];
$description=$row["description"];
$vpc=$row["vpc"];
$package_qty=$row["package_qty"];
$location=$row["location"];
$min=$row["min"];
$max=$row["max"];

I want the output to be sorted by "location". When I do the Order By location statement, the first select statement only pulled out one row from the database. Is it possible for me to put the output somewhere, re-sort it, and then output it?

Thanks,
Jeff

coopster

11:23 pm on Aug 18, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Why not use a JOIN in your query statement instead and pull all the data once, then loop through the rows?

jeffgman

3:40 am on Aug 19, 2004 (gmt 0)

10+ Year Member



Would you be able to give me some examples or hints at how I would make that work?

Thanks,
Jeff