Quote:
Originally Posted by chazzy69
Anyway the line im having trouble with is -
$sql = "SELECT var1, var2, var3 FROM table_name WHERE suburb="$suburb[$counter]" ;
The trouble here is that you are messing up the quotes.
If you were to view this in an editor that can highlight PHP, it should become very obvious, as the code following that line would be highlighted as a string.
When you use double quotes, there is no need to close the quotes to insert a variable, you can just put it right in there and PHP will parse it. To make absolutely sure there is not problem when you do this, it's best to enclose the variable in brackets. Like:
-
$sql = "SELECT var1, var2, var3
-
FROM table_name
-
WHERE suburb={$suburb[$counter]}";
And if "suburb" is a string that needs to be quoted in the SQL statement, you need to either use single-quotes
(as putting a double quote would close the string, rather than add the quote to it) or escaped double quotes.
-
$sql = "... WHERE suburb='{$suburb[$counter]}'";
-
$sql = "... WHERE suburb=\"{$suburb[$counter]}\"";
Quote:
Originally Posted by chazzy69
i know it wont work because of this line -
This, in no way related to the previous error, is because the second "pcode" you are trying to fetch an element from is not designated as a variable.
All variables start with a dollar-sign ($). That is how PHP recognises variables. If you forget it, PHP will assume it is either a constant, or a string. (Always the latter if it happens to be inside a string.)