Re: Couple of small questions
| From: | David Robley | Date: | Mon, 20 Nov 2000 23:54:32 +0000 |
| Subject: | Re: Couple of small questions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-26356@lists.php.net to get a copy of this message | ||
On Mon, 20 Nov 2000, Website4S@aol.com wrote:
> In a message dated 20/11/2000 10:24:44 GMT Standard Time, jeremy@nirvani.net
> writes:
>
> << select sum(Gram) from tablename;
>
> :)
> -jeremy brand >>
>
> Ok I am doing this but something still isn`t working, this is the code I have
> anyone spot a mistake?
>
> $SQLStatement = "SELECT SUM(Gram) FROM Purdue";
>
> $SQLConn = mysql_connect("", "", "") or die ("Could
> not connect to
> database");
>
> $db = mysql_select_db("", $SQLConn) or die ("Couldn`t select
> database");
>
> $KL = mysql_query($SQLStatement) or die ("Invalid Query");
>
>
> mysql_close ($SQLConn);
> echo ($KL);
You are only getting the result pointer here in $KL. And you'll probably
need to use an alias in the query to be able to access the result of a
SUM. So:
$SQLStatement = "SELECT SUM(Gram) AS howmuch FROM Purdue";
$SQLConn = mysql_connect("", "", "") or die ("Could not connect
to database");
$db = mysql_select_db("", $SQLConn) or die ("Couldn`t select database");
$KL = mysql_query($SQLStatement) or die ("Invalid Query");
// Only one row will be returned
$row = mysql_fetch_array($KL);
extract($row);
mysql_close ($SQLConn);
echo ($howmuch);
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA