Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
apple
Forum Newbie
Posts: 21 Joined: Wed Mar 03, 2004 12:50 am
Contact:
Post
by apple » Thu May 20, 2004 1:56 am
This is my code:
Code: Select all
<?php
$query = "SELECT names_id, first_name, last_name FROM name AS n, company AS c WHERE c.names_id = n.{$_SESSION['id']}";
?>
This is the error
Code: Select all
Unknown column 'n.2' in 'where clause'
What is the right code?
apple
Forum Newbie
Posts: 21 Joined: Wed Mar 03, 2004 12:50 am
Contact:
Post
by apple » Thu May 20, 2004 2:12 am
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu May 20, 2004 2:14 am
what are you trying to "paste" in there? what's the structure of table "name"
apple
Forum Newbie
Posts: 21 Joined: Wed Mar 03, 2004 12:50 am
Contact:
Post
by apple » Thu May 20, 2004 2:18 am
Database: HRM
Table: names
id
first_name
last_name
email
registration_date
Table: company
id
names_id
company_name
address
phone1
phone2
apple
Forum Newbie
Posts: 21 Joined: Wed Mar 03, 2004 12:50 am
Contact:
Post
by apple » Thu May 20, 2004 2:20 am
Thanks a lot
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu May 20, 2004 2:25 am
what do you mean by the session data?
apple
Forum Newbie
Posts: 21 Joined: Wed Mar 03, 2004 12:50 am
Contact:
Post
by apple » Thu May 20, 2004 2:29 am
Code: Select all
n.{$_SESSIONї'id']}";
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu May 20, 2004 2:31 am
that isn't a field in your names table.
try
Code: Select all
$query = "SELECT names_id, first_name, last_name FROM name AS n, company AS c WHERE c.names_id = '{$_SESSION['id']}'";
[edit:forget that]
try this instead.
Code: Select all
$query = "SELECT names_id, first_name, last_name FROM name AS n, company AS c WHERE c.names_id = n.id";
apple
Forum Newbie
Posts: 21 Joined: Wed Mar 03, 2004 12:50 am
Contact:
Post
by apple » Thu May 20, 2004 2:38 am
I really appreciate your help. Thank you so much.
I try your code. This is the ERROR...
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'c.name_id = '2'' at line 1
Do you have any other options?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu May 20, 2004 2:42 am
I edited my previous post..
I'm assuming here that company.name_id is supposed to match name.id, yes?
apple
Forum Newbie
Posts: 21 Joined: Wed Mar 03, 2004 12:50 am
Contact:
Post
by apple » Thu May 20, 2004 2:48 am
SESSION came from the names (table)
n.id = c. names_id
launchcode
Forum Contributor
Posts: 401 Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:
Post
by launchcode » Thu May 20, 2004 6:38 am
What exactly do you want your Query to return? In your very first post you are trying to select the Names data based on a given ID (stored in a session variable) - is this correct?