0

I have 2 table and i want to pull data from both of them. This is sample for my table structure:

Table tbl_a = id, time, note, customer Table tbl_b = id, time, name, surname, note

This is my mysql request:

Select * from tbl_a left join tbl_b on tbl_a.customer=tbl.b=id where tbl_a.id=5;

When i run this query directly from mysql i can see result exactly as i want but i dont know how to display it in my php page.

i am doing it like this:

$sql = mysql_query("Select * from tbl_a left join tbl_b on tbl_a.customer=tbl.b=id where tbl_a.id=5");
$data = mysql_fetch_array($sql);
echo $data[id]." - ".$data[time]." - ".$data[note]." - ".$data[customer]." - ".$data[id]." - ".$data[name]." - ".$data[surname]." - ".$data[note];

i know that column names that are repeated could not be used again but i dont know what the right way is.

asked Nov 22, 2013 at 8:32

1 Answer 1

0

I suggest instead of using the ALL (*). just type the column names with an AS attached such as: TableA.id AS TableAId,TableB.id AS TableBId and so on.

answered Nov 22, 2013 at 9:59
2
  • Thank you a lot. is there any quicker way to do that becouse i have about 40 column? if not i will use your suggestion Commented Nov 22, 2013 at 12:35
  • Not that I know of. hopefully someone can shed some light if there's a way. Commented Nov 22, 2013 at 13:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.