Skip navigation links

MySQL Forums :: PHP :: where clause is ambiguous


Advanced Search

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>";



return($city_select);

}


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

Options: ReplyQuote


Subject Written By Posted
where clause is ambiguous teddy blachard 03/03/2008 01:05PM
Re: where clause is ambiguous Peter Brawley 03/03/2008 02:59PM
Re: where clause is ambiguous Peter Brawley 03/10/2008 11:45AM
Re: where clause is ambiguous teddy blachard 03/10/2008 10:41AM
Re: where clause is ambiguous teddy blachard 03/17/2008 11:00AM
Re: where clause is ambiguous Peter Brawley 03/17/2008 05:14PM
Re: where clause is ambiguous teddy blachard 03/18/2008 02:51PM
Re: where clause is ambiguous Peter Brawley 03/18/2008 02:57PM
Re: where clause is ambiguous teddy blachard 03/18/2008 03:04PM
Re: where clause is ambiguous Peter Brawley 03/18/2008 08:09PM


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.