mysql - Get column with same name from multiple tables using PHP -
ok, here have right now:
$stuff = mysql_query("select * table1, table2") or die(mysql_error()); if ($info = mysql_fetch_array($stuff)) { $table1id = $info['table1.id']; $table2id = $info['table2.id']; }
my problem not work. nothing. , when this:
$stuff = mysql_query("select * table1, table2") or die(mysql_error()); if ($info = mysql_fetch_array($stuff)) { $table1id = $info['id']; $table2id = $info['id']; }
it same id (of course). how id of first table , second table when have same name?
mysql_fetch_array gives list using both names , numeric values, names going 'id' both, first 1 lost unless use alias rename them in sql. have numeric index, use $info[0]
, $info[1]
using alias instead:
$query = "select table1.id id1, table2.id id2 table1, table2";
and use $info['id1']
, $info['id2']
(notice: mysql_*-functions deprecated)
Comments
Post a Comment