sql - php match cells from 2 databases and pull out cell info -
i have users database , person database
in users database have following cells
id, firstname, lastname, person_id
in person database have following cells
id, firstname, phone
i show out phone person db based on person_id users db (the id in users db , person db not same therefore need match ids thru users.person_id phone)
this how far - without luck though... nothing shows:
$query = "select person_id user person.id=$user_person_id"; $result = mysql_query($query); $line = mysql_fetch_object($result); echo "phone: $line[$phone]";
hopefully, if understand question well, sql joins you. here using left join. try read more joins.
$sql = "select `users`.`id`, `users`.`firstname`, `users`.`lastname`, `person`.`phone` `users` left join `person` on `users`.`person_id` = `person`.`id`"; $query = $mysql_query ($sql); $result = $mysql_fecth_assoc ($query); echo 'phone: ', $result['phone'];
here errors:
- from comments fetching results object yet displaying array. $line =
$mysql_fetch_object($result);
- you using variable array key.
$line[$phone];
try these new codes. hope should work.
Comments
Post a Comment