PDA

View Full Version : SQL Query Error


macleodjb
04-26-2007, 04:05 AM
I have this query that seems to not want to take a variable in replace of "jobnumber". I want it to be something like this


WHERE `JobName` = $JobName LIMIT 1


This is the code i have for my query


$query = 'SELECT ji.`JobName`, ji.`JobNumber`, ji.`JobStreet`, ji.`JobStreet2`, ji.`JobCity`, ji.`JobState`, ji.`JobZip`, ji.`ContractorName`, ji.`ContractorStreet`, ji.`ContractorStreet2`, ji.`ContractorCity`, ji.`ContractorState`, ji.`ContractorZip`, ji.`ArchitectName`, ji.`ArchitectStreet`, ji.`ArchitectStreet2`, ji.`ArchitectCity`, ji.`ArchitectState`, ji.`ArchitectZip`, js.`InstallDate` FROM `jobinfo` as ji JOIN `jobstatus` as js ON ji.`JobNumber` = js.`JobNumber` WHERE ji.`JobNumber` = 1234 LIMIT 1';


How can i get the query to accept a variable in replace of 1234.

Thanks in advance.

Fumigator
04-26-2007, 04:10 AM
Use double-quotes.

Here are the rules for imbedding variables within a string:

http://us.php.net/manual/en/language.types.string.php

Alternatively you can end the string and concantenate the variable onto the string like this:


$query = "SELECT * FROM table WHERE ID = " . $varID . " AND NAME = " . $varName;