Jump to content

MYSQL Functions


The-Last-Escape

Recommended Posts

have been lately trying to do mysql functions.  I am just wondering why none of them have not been working, is there something I am doing wrong.

I have tried using sum (the total amount of what is in rows)

and LAST which is meant to get the last row that was entered, but nothing is working.

$lastbills = "SELECT LAST(amount) FROM transactions WHERE type = 'Bill' AND userid = '" . $_SESSION['cymember'] . "' LIMIT 1;";

$lastbillq = mysql_query($lastbills);

echo $lastbillsq;

This is just one example of me trying to get the last occurence of something.

I know queries aren't always the easiest to work with, but some of this stuff would be much simpler if I could get the hang of sql based specific functions that I can use straight in the query.  Saving unnecessary time, I just have to learn to use them properly, any advice is greatly appreciated.  Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/49347-mysql-functions/
Share on other sites

I've been unable to locate a LAST function, but here's an example using SUM()

<?php
$sql = "SELECT SUM(amount) as total FROM transactions WHERE type='Bill'";
$res = mysql_query($sql);                   // get query results
$row = mysql_fetch_assoc($res);         // get first (in this case the only) row

echo $row['total'];                             // echo total field
?>

Link to comment
https://forums.phpfreaks.com/topic/49347-mysql-functions/#findComment-241810
Share on other sites

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.