Jump to content

Recommended Posts

[/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?

Link to comment
https://forums.phpfreaks.com/topic/210238-join-issues/
Share on other sites

#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

Link to comment
https://forums.phpfreaks.com/topic/210238-join-issues/#findComment-1097128
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/210238-join-issues/#findComment-1097135
Share on other sites

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.