<?php header('Content-type: text/html; charset=utf-8'); $db_host=""; $db_user=""; $db_password=""; $db_name = ""; $mysqli = new mysqli($db_host, $db_user, $db_password, $db_name); if (mysqli_connect_errno()) { printf("Ошибка соединения: %s\n", mysqli_connect_error()); exit; } $mysqli->set_charset("utf8"); if ($stmt = $mysqli->query('SELECT * FROM vtiger_contactdetails, vtiger_timesheet, vtiger_timesheetcf WHERE vtiger_contactdetails.contactid = vtiger_timesheet.cf_2295 AND vtiger_timesheet.cf_2295 = vtiger_timesheet.timesheetid')) { while($row = $stmt->fetch_assoc()){ echo $row['lastname'].' '.$row['cf_2295'].'<br />'; } } ?> 

The code works without vtiger_timesheet, and the last condition
AND vtiger_timesheet.cf_2295 = vtiger_timesheet.timesheetid
It is necessary that all the tables be connected and that the conditions work.
Tell me how to write requests?

  • First, perform a complete query in mysql directly. - Hardc0re

1 answer 1

Use JOIN .

Here is a nice article about table joins. Explanation of SQL JOIN joins.

 SELECT * FROM vtiger_contactdetails JOIN vtiger_timesheet ON vtiger_contactdetails.contactid = vtiger_timesheet.cf_2295 JOIN vtiger_timesheetcf ON vtiger_timesheet.cf_2295 = vtiger_timesheet.timesheetid 

somehow, perhaps ORDER BY at the end still needs to be used .. it is necessary to test

  • Well, now I will look, thanks - Dmitry Kut
  • vtiger_timesheet another table? Esli Yes I will write a sample in the message - Volodymyr
  • Yes, this is another table. 3 tables are involved in this code vtiger_timesheet vtiger_contactdetails vtiger_timesheetcf - Dmitry Kut
  • Super, everything works, thanks - Dmitry Kut