Jump to content

need help of getting data from sql query


prakash

Recommended Posts

I have a sql query like

select table1.id, table2.id, field1, field2, field3 from table1, table2 where field1=table2.id order by field3

so my question is

how to to fetch table1.id or table2.id ?

using following is not working at all

 

$data1=$each_row['table1.id'];

$data2=$each_row['table2.id'];

 

so how can I get the same value above??

 

Link to comment
https://forums.phpfreaks.com/topic/81651-need-help-of-getting-data-from-sql-query/
Share on other sites

Maybe something like:

select table1.id as table1_id, table2.id as table2_id, field1, field2, field3 from table1, table2 where program_id=table2.id order by field3

 

Then:

$data1=$each_row['table1_id'];
$data2=$each_row['table2_id'];

 

Edit: On a side note, please tell me you edited your code down for simplicity of display. Otherwise, don't expect what you currently have to work at all.

 

Maybe something like:

select table1.id as table1_id, table2.id as table2_id, field1, field2, field3 from table1, table2 where program_id=table2.id order by field3

 

Then:

$data1=$each_row['table1_id'];
$data2=$each_row['table2_id'];

 

Edit: On a side note, please tell me you edited your code down for simplicity of display. Otherwise, don't expect what you currently have to work at all.

 

 

this is not working

while checking through phpmyadmin it output error like "Unknown column 'table2_id' in 'where clause' "

any help?

I was just being lazy, you need to finish the query. The [...] signified something that I removed. Putting the rest in:

SELECT table1.id AS table1_id, table2.id AS table2_id, field1, field2, field3 FROM table1, table2 WHERE field1=table2.id ORDER BY field3

I was just being lazy, you need to finish the query. The [...] signified something that I removed. Putting the rest in:

SELECT table1.id AS table1_id, table2.id AS table2_id, field1, field2, field3 FROM table1, table2 WHERE field1=table2.id ORDER BY field3

 

there is just the differences of AS being capitalize and this is not working at all

any suggestion?

No, it's just easier to read. You can do it like as, As, aS or AS. It's case insensitive.

 

Edit:

Daniel0, I'm pretty sure I already suggested that. The only difference is the capitalization of the mysql statements; which I believe makes no difference?

Oh, I'm sorry. I didn't notice.

 

I'm not sure if you can do this though:

from table1, table2 where

No, it's just easier to read. You can do it like as, As, aS or AS. It's case insensitive.

 

Edit:

Daniel0, I'm pretty sure I already suggested that. The only difference is the capitalization of the mysql statements; which I believe makes no difference?

Oh, I'm sorry. I didn't notice.

 

I'm not sure if you can do this though:

from table1, table2 where

 

read the 7th post

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.