Search code examples
phpmysqlsmsinbox

how to relation table inbox with table phonebook?


i have problem with my project for my office

my table

tbl_phonebook
number     name
0814432     ahmad

tbl_inbox
SenderNumb     text
0814432          coba coba
0942042          sekalian

how to display data from the table inbox if the same number in the inbox with the number in the phonebook table displays the name and number in the inbox if there are no / not the same as the number in phonebook table shows the number of the original sender

tq before


Solution

  • I'm not completely sure I understand your problem. I think you want to use LEFT JOIN to see if the record exists in the phonebook table.

    And perhaps use IFNULL to show the name or the sendernumb:

    SELECT i.sendernumb,
        IFNULL(p.name,i.sendernumb) name,
        i.text text
    FROM tbl_inbox i
        LEFT JOIN tbl_phonebook p ON i.SenderNumb = p.number