Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Combine the results into another structure before outputting as JSON. Use <a href="http://php.net/array_values" rel="noreferrer"><code>array_values</code></a> to convert the type IDs into an array of type IDs. Also, fix that <a href="http://unixwiz.net/techtips/sql-injection.html" rel="noreferrer">SQL injection</a> vulnerability. Using <a href="http://php.net/PDO" rel="noreferrer">PDO</a>, and assuming the error mode is <a href="http://www.php.net/manual/en/pdo.setattribute.php" rel="noreferrer">set</a> to PDO::ERRMODE_EXCEPTION:</p> <pre><code>$id = $_POST['id']; try { $contractQuery = $db-&gt;prepare("SELECT contracts.po_number, contracts.start_date, contracts.end_date, contracts.description, contracts.taa_required, contracts.account_overdue, jobs.id AS jobs_id, jobs.job_number, companies.id AS companies_id, companies.name AS companies_name FROM contracts LEFT JOIN jobs ON contracts.job_id = jobs.id LEFT JOIN companies ON contracts.company_id = companies.id WHERE contracts.id = ? ORDER BY contracts.end_date"); $typesQuery = $db-&gt;prepare("SELECT types_id FROM contracts_types WHERE contracts_id = ?"); $contractQuery-&gt;execute(array($id)); $typesQuery-&gt;execute(array($id)); $result = array(); $result['contracts'] = $contractQuery-&gt;fetchAll(PDO::FETCH_ASSOC); $result['types'] = array_values($typesQuery-&gt;fetchAll(PDO::FETCH_NUM)); echo json_encode($result); //return json } catch (PDOException $exc) { ... } </code></pre> <p>If <code>$contractQuery</code> returns at most one row, change the fetch lines to:</p> <pre><code> $result = $contractQuery-&gt;fetch(PDO::FETCH_ASSOC); $result['types'] = array_values($typesQuery-&gt;fetchAll(PDO::FETCH_NUM)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload