radar Posted August 9, 2010 Share Posted August 9, 2010 [/code] $sql = "SELECT d.id, d.d_id, d.reg_price, d.sale_price, d.title, d.img, d.img_cnt, d.start_date, d.end_date, d.min_qty, d.max_qty, d.aboutTxt SUM(o.id) AS orders_cnt, FROM deals AS d WHERE start_date <= '".$now."' AND end_date >= '".$end_time."' AND status=1 LEFT JOIN orders AS o ON o.d_id = d.id GROUP BY o.d_id d.id ORDER BY d.start_date"; [/code] when I echo this out, it comes up with: SELECT d.id, d.d_id, d.reg_price, d.sale_price, d.title, d.img, d.img_cnt, d.start_date, d.end_date, d.min_qty, d.max_qty, d.aboutTxt, SUM(o.d_id) AS orders_cnt FROM deals AS d WHERE d.start_date <= '2010-08-09' AND d.end_date >= '2010-08-02'AND status=1 LEFT JOIN orders AS o ON o.d_id = d.id GROUP BY o.d_id d.id ORDER BY d.start_date and when i run that through phpMyadmin it gives me a syntax error, i magine with the WHERE clause. on top of this error, is there any way to find out percentages in the query? ie what % is d.sale_price of d.reg_price and is it possible to do math involved too such as MATH(d.max_qty - orders_cnt) as remaining or something like that? Quote Link to comment https://forums.phpfreaks.com/topic/210238-join-issues/ Share on other sites More sharing options...
Maq Posted August 9, 2010 Share Posted August 9, 2010 and when i run that through phpMyadmin it gives me a syntax error, i magine with the WHERE clause. What's the error...? Quote Link to comment https://forums.phpfreaks.com/topic/210238-join-issues/#findComment-1097124 Share on other sites More sharing options...
radar Posted August 9, 2010 Author Share Posted August 9, 2010 #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN orders AS o ON o.d_id = d.id GROUP BY o.d_id, d.id ORDER BY d.start_da' at line 6 phpmyadmin code breakdown SELECT d.id, d.d_id, d.reg_price, d.sale_price, d.title, d.img, d.img_cnt, d.start_date, d.end_date, d.min_qty, d.max_qty, d.txtAbout, d.status, SUM( o.d_id ) AS orders_cnt FROM deals AS d WHERE d.start_date <= '2010-08-09' AND d.end_date >= '2010-08-02' AND d.status =1 LEFT JOIN orders AS o ON o.d_id = d.id GROUP BY o.d_id, d.id ORDER BY d.start_date LIMIT 0 , 30 Quote Link to comment https://forums.phpfreaks.com/topic/210238-join-issues/#findComment-1097128 Share on other sites More sharing options...
radar Posted August 9, 2010 Author Share Posted August 9, 2010 I figured the error out, it was where i had the WHERE clause, it needed to be right after left join i guess. I also figured out the mathmatics for figuring out one of the math problems... Now through the SQL query line, does anyone know how to figure out percentage? specifically what percent of d.reg_price is d.sale_price in php i do it like this: $count1 = $num_amount / $num_total; $count2 = $count1 * 100; $count = number_format($count2, 0); return $count; so would i do something like d.sale_price / d.reg_price * 100 and call it good? I tried that, and if it's an even % like 50% it works well. Otherwise, it doesnt really work at all. Quote Link to comment https://forums.phpfreaks.com/topic/210238-join-issues/#findComment-1097135 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.