php - mysql left join not return all left table row -
i have 2 tables
phonetype: phonetypeid (pk) phonetyepe phone: phoneid (pk) peopleid (fk) phonetypeid (fk) areacode number` for specific peopleid return phonetypes , if peopleid has number diplay it, if not empty. like:
phonetype phonetypeid areacode number company 1 111 11111 fax 2 home 3 222 222222 mobile 4 here prepared statement:
$stmt = $conn->prepare("select * phonetype left join phone on phonetype.phonetypeid=phone.phonetypeid phone.peopleid = ?; "); if ( !$stmt ) {die(printf("error: %s.\n", mysqli_stmt_error($stmt) ) );} else if ( !$stmt->bind_param('i', $peopleid) ) {die(printf("error: %s.\n", mysqli_stmt_error($stmt) ) );} but way have
phonetype phonetypeid areacode number company 1 111 11111 home 3 222 222222 what doing wrong? ps first join!! thanks!!
edit (this question follows other question [display data database in specific order: php or mysql? . after reading answers of gravel, robbie averill, maximus2012 , miken32 understood better design have dedicate table phonetype, , use foreign key in phone table. thinking different scenario, asked new question. if thinks duplicate , there way join 2 question, it. again took time me.)
in query;
select * phonetype left join phone on phonetype.phonetypeid=phone.phonetypeid phone.peopleid = ? ...the where clause condition on rightmost table remove rows rightmost table has no value, negating left join.
what want add condition left join's on clause instead, allowing empty values of phone still show up;
select * phonetype left join phone on phonetype.phonetypeid=phone.phonetypeid , phone.peopleid = ?
Comments
Post a Comment