confused about sql join

139
February 14, 2018, at 1:49 PM

i have this VIEW MODAL it views the data from the table by ID my problem is if i add an update (as you can see in the image) it doesnt show to in the table updatedby and update: i tried joining in mysql but it only fetch the dateupdated column in my 2nd table. here is my second add_update table and this is my first table document table the foreign key is document_id as you can see.

here is my query in mysql

$query = "SELECT document.document_id, document.document_name, document.document_type,
   document.document_from,document.document_to,document.document_recieved, document.document_date,document.document_dater,
   document.document_status,document.document_signatories,document.document_remarks,document.document_encoded, add_update.document_date_update,
   add_update.document_update,add_update.document_updatedby FROM document LEFT JOIN add_update ON document.document_id = add_update.document_id WHERE
    document.document_id = '".$_POST["document_id"]."'";
  $result = mysqli_query($connection, $query);
Answer 1

I believe you have to trace the code. Firstly you can do

print_r($result)

to check whether the query contains all the columns. And then if it already gives you the right result please check your form, to check whether it outputs the right variable.

It is also a good practice to use parameter binding:

$query = $mysqli->prepare('SELECT document.document_id,  
  document.document_name, 
  document.document_type, 
  document.document_from,
  document.document_to,
  document.document_recieved, 
  document.document_date,
  document.document_dater,    
  document.document_status,
  document.document_signatories,
  document.document_remarks,
  document.document_encoded,
  add_update.document_date_update, 
  add_update.document_update, 
  add_update.document_updatedby 
  FROM document 
  LEFT JOIN add_update ON document.document_id = add_update.document_id 
  WHERE
  document.document_id = ?');
$query->bind_param('s', $_POST["document_id"]);
$result = $query->execute();
Rent Charter Buses Company
READ ALSO
How to block access from outside to .php files in wordpress?

How to block access from outside to .php files in wordpress?

on my wordpress website i have some criticalphp files which include code like:

163
mysql update and set sum value of last 8 hours of the current row

mysql update and set sum value of last 8 hours of the current row

Hi I would like to count the sum of chat_duration from 8 hours ago of the current data I have : agent text start_time datetime end_time datetime chat_duration bigint

217
SQL Query - Filter with different type

SQL Query - Filter with different type

I'm very stuck to create my sql queryIf someone can help me or advice me

152
how to get a grand child from parent in php

how to get a grand child from parent in php

Hi all i need a help i need to display a grand child from parent id that means one id=2 has a child id=3 and child id=3 has a child id=4 (here child id=3 is parent id for child id=4)

172