countrygyrl Posted April 2, 2010 Share Posted April 2, 2010 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 More sharing options...
Jax2 Posted April 2, 2010 Share Posted April 2, 2010 $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]'"; $result=mysql_query($sql); echo $total; something like that? Link to comment https://forums.phpfreaks.com/topic/197312-passing-query-results-to-php/#findComment-1035618 Share on other sites More sharing options...
countrygyrl Posted April 2, 2010 Author Share Posted April 2, 2010 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; Link to comment https://forums.phpfreaks.com/topic/197312-passing-query-results-to-php/#findComment-1035649 Share on other sites More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 $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']; } } Link to comment https://forums.phpfreaks.com/topic/197312-passing-query-results-to-php/#findComment-1035655 Share on other sites More sharing options...
countrygyrl Posted April 2, 2010 Author Share Posted April 2, 2010 OMG thank you so much!!!! You have no idea, I have been working on this syntax for three days. I just about peed my pants when I got the result I was looking for lol Link to comment https://forums.phpfreaks.com/topic/197312-passing-query-results-to-php/#findComment-1035663 Share on other sites More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 3 days? There are VERY clear examples of this in the manual. Link to comment https://forums.phpfreaks.com/topic/197312-passing-query-results-to-php/#findComment-1035665 Share on other sites More sharing options...
countrygyrl Posted April 2, 2010 Author Share Posted April 2, 2010 um yeah the manual, we don't get along so good. I searched and searched and couldn't find anything that worked. Link to comment https://forums.phpfreaks.com/topic/197312-passing-query-results-to-php/#findComment-1035666 Share on other sites More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 You'd probably better start making up with the manual then, its a php programmers best friend. A very well written & functional one at that too IMO. Link to comment https://forums.phpfreaks.com/topic/197312-passing-query-results-to-php/#findComment-1035673 Share on other sites More sharing options...
countrygyrl Posted April 2, 2010 Author Share Posted April 2, 2010 lol I will try Link to comment https://forums.phpfreaks.com/topic/197312-passing-query-results-to-php/#findComment-1035680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.