MySQL Forums
Forum List  »  PHP

where clause is ambiguous
Posted by: teddy blachard
Date: March 03, 2008 01:05PM

So I'm getting this error.

ERROR: Column 'state' in where clause is ambiguous

I know this means that I have more than one table in which the column header 'state' is used.

Here is the code snippet:

$state_select = buildStateSelect($state);
$city_select = buildCitySelect($state,$city);

function buildCitySelect($state,$city) {

if ($state) {
$qry = "select DISTINCT city from employees where state='$state' order by 'city' asc";
else {
$qry = "select DISTINCT city from employees order by 'city' asc";
$res = mysql_query($qry) or die("ERROR: ".mysql_error());
$cnt = mysql_num_rows($res);

$city_select = "<select name=\"city\" onchange=submit();>";
if (!$city) {
$cur_sel = "<option value=\"\" selected>All</option>\n";
else {
$cur_sel = "<option value=\"$city\" selected>$city</option>\n";
$cur_sel .= "<option value=\"\">All</option>\n";

$city_select .= $cur_sel;

do {
if ($emp_city) {
$city_select .= "<option value=\"$emp_city[city]\">$emp_city[0]</option>\n";
}while($emp_city = mysql_fetch_array($res));
$city_select .= "</select>";



I've tried several things like employee.state or state="'$_SESSION['state']'" but nothing has worked thus far. Any suggestions?

Options: ReplyQuote

Written By
where clause is ambiguous
March 03, 2008 01:05PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.