Page 1 of 1

Arg. Getting results is "ambiguous"?

Posted: Wed Mar 24, 2004 9:53 pm
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;
?>

Posted: Wed Mar 24, 2004 10:01 pm
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

Posted: Wed Mar 24, 2004 10:05 pm
by Steveo31
Thanks for tryin', but nope.

:)

Posted: Wed Mar 24, 2004 10:09 pm
by bawla
another failed attempt

scratches number 112th on the wall :cry:

Posted: Wed Mar 24, 2004 10:16 pm
by Steveo31
Cmon man... keep your head up. You only have 74 posts, so where are you getting 112? ;) :D

Posted: Wed Mar 24, 2004 10:19 pm
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

Posted: Wed Mar 24, 2004 11:15 pm
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)

Posted: Thu Mar 25, 2004 9:27 am
by Steveo31
Ahh okay. Makes perfect sense.