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
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.

 

Link to comment
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.

 

 

this is not working

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

any help?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.