• How to use a query to lookup in a different table?

    SapnaVishwas Member

    The principle of the JOIN is to take to tables and put them next to each other so that the records in the LEFT table are next to the records in the RIGHT table where some field in the two is equal. With the LEFT JOIN we are saying that even if there isn’t a row in the RIGHT table that matches the LEFT still include the record from the left and just return NULLS for the table on the RIGHT.

    In the above IN CALL is the LEFT table and EXTENSION is the RIGHT table.

    You might need to add code to your PHP script to check that the NAMEOFPERSONFIELD field has a value and if it does not then use the calling party value. We can modify the SQL script to work this out for you but one step at a time.

    See if this works for you and then we take it from there.

    Hint: run the query in a Query Tool (MySQL Workbench, SQLYog, Heidi etc). This will give you an idea of the data coming back and whether it is what you want. You can then fine tune the query before including it in your code.

    $result = query("SELECT 
      i.month,
      i.day,
      i.time,
      i.hrs,
      i.mins,
      i.sec,
      i.callingparty,
      i.leaddigit,
      i.calledno,
      i.calltype,
      i.calledparty,
      i.transferext,
      i.trunk,
      i.year,
      i.call_ID,
      i.active,
      i.property_id,
      i.insertdate,
      e.NAMEOFPERSONFIELD
    FROM incall i LEFT JOIN extension e ON   i.callingparty = e.EXTENTIONTABLENUMBERFIELD
    WHERE property_id ='%d'
    ORDER BY call_ID",$_SESSION['property']);
    
Viewing 0 reply threads
  • You must be logged in to reply to this topic.