Mysql Query (måske JOIN)
jeg sidder og arbejder lidt på en select som jeg gerne skulle have kogt ned til en enkelt pæn query der er nemmere at sortere på, jeg kunne forstille mig det er noget join jeg skal kigge på..det jeg gerne vil opnå er at kunne lave en ORDER BY på category_name og manufactures_name
Jeg har følgende querys:
$varelinier = mysql_query ( "SELECT products_name, products_id, final_price, SUM(products_quantity) AS total_quantity FROM zen_orders_products WHERE orders_id IN ($final_ids) GROUP BY products_name" )or die(mysql_error());
while($varelinie = mysql_fetch_array($varelinier)) {
echo "<tr>";
echo "<td>" . $varelinie['products_id'] . "</td>";
echo "<td>" . $varelinie['products_name'] . "</td>";
echo "<td>" . $varelinie['total_quantity'] . "</td>";
$cat_id = mysql_query ( "select master_categories_id FROM zen_products WHERE products_id = $varelinie[products_id]" )or die(mysql_error());
$row20 = mysql_fetch_assoc($cat_id);
$par_id = mysql_query ( "select parent_id FROM zen_categories WHERE categories_id = $row20[master_categories_id]" )or die(mysql_error());
$row21 = mysql_fetch_assoc($par_id);
$cat_name = mysql_query ( "select categories_name FROM zen_categories_description WHERE categories_id = $row21[parent_id]" )or die(mysql_error());
$row22 = mysql_fetch_assoc($cat_name);
echo "<td>" . $row22['categories_name'] . "</td>";
$man_id = mysql_query ( "select manufacturers_id FROM zen_products WHERE products_id = $varelinie[products_id]" )or die(mysql_error());
$row10 = mysql_fetch_assoc($man_id);
$man_name = mysql_query ( "select manufacturers_name FROM zen_manufacturers WHERE manufacturers_id = $row10[manufacturers_id]" )or die(mysql_error());
$row11 = mysql_fetch_assoc($man_name);
echo "<td>" . $row11['manufacturers_name'] . "</td>";
echo "<td>" . $varelinie['total_quantity'] . $order_supplier . "</td>";
echo "</tr>";
Tak på forhånd