Page 1 of 1

Please Help!

Posted: Thu May 20, 2004 1:56 am
by apple
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?

Please Help

Posted: Thu May 20, 2004 2:12 am
by apple
Please Help Me!

Posted: Thu May 20, 2004 2:14 am
by feyd
what are you trying to "paste" in there? what's the structure of table "name"

This is the Structure

Posted: Thu May 20, 2004 2:18 am
by apple
Database: HRM

Table: names
id
first_name
last_name
email
registration_date


Table: company
id
names_id
company_name
address
phone1
phone2

I was trying to get the SESSION data

Posted: Thu May 20, 2004 2:20 am
by apple
Thanks a lot

Posted: Thu May 20, 2004 2:25 am
by feyd
what do you mean by the session data?

I think somewhere is wrong on this code

Posted: Thu May 20, 2004 2:29 am
by apple

Code: Select all

n.&#123;$_SESSION&#1111;'id']&#125;";

Posted: Thu May 20, 2004 2:31 am
by feyd
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";

I try your code

Posted: Thu May 20, 2004 2:38 am
by apple
:D 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?

Posted: Thu May 20, 2004 2:42 am
by feyd
I edited my previous post..

I'm assuming here that company.name_id is supposed to match name.id, yes?

Posted: Thu May 20, 2004 2:48 am
by apple
SESSION came from the names (table)

n.id = c. names_id

Posted: Thu May 20, 2004 6:38 am
by launchcode
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?