Arg. Getting results is "ambiguous"?

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
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Arg. Getting results is "ambiguous"?

Post by Steveo31 »

Choppy and not well set up yet just to get it to work, but it's not. I run this code, and get an error:

Column: 'name' in field list is ambiguous

The DB is set up like DB-'vacation', tables 'jamaica', 'bolivia', and 'haiti', with 'name' and 'id' inside. I need to see if the name of the "searchterms" variable is in the DB.. I thought this might work, but no go.

Code: Select all

<?php

//connect to the DB:
$db = mysql_connect('localhost', 'root') or die('Error.  '.mysql_error());
mysql_select_db('vacation', $db) or die(mysql_error());

//set up short variable from posted texfield:
$searchterms = $_POST['searchterms'];

//query setup:
$sql = 'SELECT name FROM haiti, jamaica, bolivia';
$sendSql = mysql_query($sql) or die(mysql_error());

$resultarray = mysql_fetch_array($sendSql, MYSQL_ASSOC); 
$matches = mysql_num_rows($sendSql);

echo $matches;
?>
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

change

Code: Select all

$sql = 'SELECT name FROM haiti, jamaica, bolivia';

to

Code: Select all

$sql = 'SELECT name FROM haiti, jamaica, bolivia,$db';
but. dont trust me cuz im a newbie at this
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Thanks for tryin', but nope.

:)
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

another failed attempt

scratches number 112th on the wall :cry:
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Cmon man... keep your head up. You only have 74 posts, so where are you getting 112? ;) :D
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

i have no idea, i think i was thinking of 112th street when i was writing it, lol, i let my fingers dance on the keyboard, they play wut they want, dodododododo
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

It's saying name is ambiguous as it doesn't know which name you mean in $sql = 'SELECT name FROM haiti, jamaica, bolivia'; as all the tables have a column called name. So you'de want to do something like,
$sql = 'SELECT h.name, j.name, b.name FROM haiti h, jamaica j, bolivia b';

(and you'll probably want some form of WHERE in there too if you're searching for stuff :o)
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Ahh okay. Makes perfect sense.
Post Reply