Jump to content

Passing Query results to PHP


countrygyrl

Recommended Posts

I have a query that works in phpmyadmin but I can't figure out how to pull the result from it, I am also pretty sure there is a prettier way to write the sql query but hey, it works and my daddy always taught me not to fix it if it isn't broke.  Soo if someone can tell me how to actually utilize this sql statement in a php page that would be great:

 

SELECT SUM(si_invoice_items.total) AS $total_invoices FROM si_invoices LEFT JOIN si_invoice_items ON si_invoices.id = si_invoice_items.invoice_id WHERE si_invoices.customer_id='$_SESSION[user_id]'

 

Link to comment
https://forums.phpfreaks.com/topic/197312-passing-query-results-to-php/
Share on other sites

Unfortunately that didn't work, this is my code right now I am getting no result.  If I take the sql statement alone and put it in the database I do get the correct result, so i know the problem is with the way I am trying to get the sql result into php

 

$result=mysql_query("SELECT SUM(si_invoice_items.total) AS $total_invoices FROM si_invoices LEFT JOIN si_invoice_items ON si_invoices.id si_invoice_items.invoice_id WHERE si_invoices.customer_id='$_SESSION[user_id]'");
$total_invoices = $total;

$sql="
  SELECT SUM(si_invoice_items.total) AS total_invoices FROM si_invoices 
  LEFT JOIN si_invoice_items ON si_invoices.id = si_invoice_items.invoice_id 
  WHERE si_invoices.customer_id='{$_SESSION['user_id']}'
";

if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    $row = mysql_fetch_assoc($result);
    echo $row['total_invioces'];
  }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.