[SOLVED]: How to combine a php variable in a sql query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ecxzqute
Forum Commoner
Posts: 29
Joined: Tue Oct 14, 2008 12:26 am

[SOLVED]: How to combine a php variable in a sql query

Post by ecxzqute »

Hey guys!,

Im currently coding php and have to produce a report. now i have this query that needs to have a condition that is stored in a variable...

here's a part of my code/query:

Code: Select all

 
    , (SUM(SHH.REG) * (SHH.DailyRate/".$regwhours.")) TotalDailyRate
    , SUM(SSH.DailyRateReg) GrandDailyRate
 
The first line produces an error..
Any ideas is very much appreciated!
Last edited by ecxzqute on Tue Jan 26, 2010 8:06 pm, edited 1 time in total.
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: How to combine a php variable in a sql query using mysql

Post by aravona »

ecxzqute wrote:
The first line produces an error..
Would be more useful if you posted the error for us :)
ecxzqute
Forum Commoner
Posts: 29
Joined: Tue Oct 14, 2008 12:26 am

Re: How to combine a php variable in a sql query using mysql

Post by ecxzqute »

im sorry for the late reply, i've been busy for the past few days..
well i've been able to solve the problem..
i figured out that i have to put single quotes ('') before and after the variable
$regwhours..

so, from , (SUM(SHH.REG) * (SHH.DailyRate/".$regwhours.")) TotalDailyRate

comes , (SUM(SHH.REG) * (SHH.DailyRate/'".$regwhours."')) TotalDailyRate
Post Reply