Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Print the values obtained in a table after self joining two table in 'php'?

Tags:

sql

php

mysql

how to print A.station_id from given code

$query="SELECT A.train_no, A.station_id, A.arrival, A.dept, B.station_id, B.arrival, B.dept FROM TIME A,TIME B WHERE A.train_no = B.train_no AND A.station_id ='KNR' AND B.station_id='CLT' ";


$rs=mysql_query($query); 

while($row = mysql_fetch_array($rs)) {

echo "</td><td>".$row['A.station_id']."</td> <td>"       .$row['A.arrival'] ."</td> <td>".$row['A.dept'] . "</td><td>".$row['B.station_id'] . "</td> <td>".$row['B.arrival'] ."</td><td>" .$row['B.dept']. "</td><td>";

}
like image 273
Amit Avatar asked Jan 18 '14 09:01

Amit


1 Answers

Most database APIs don't include the table name in the associative array keys. So you should just use $row['arrival'].

If your query is returning two arrival columns from different tables, you should give one or both of them a different alias, e.g.

SELECT a.arrival AS a_arrival, b.arrival AS b_arrival, ... Then you can refer to them as $row['a_arrival'] and $row['b_arrival'].

like image 113
Athul Raj Avatar answered Oct 31 '22 07:10

Athul Raj