Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 7th, 2005, 02:51 PM
nav nav is offline
Registered User
 
Join Date: Aug 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying the content of a query

I have just created a query but i am unsure of how to display the contents. The query below works but the answer of the query does not display.

I know it's something to do with $answer= mysql_fetch_array($result);
Any help would be much appreciated.

$sqlquery2 = "SELECT SUM(Bytes)
                FROM test
                WHERE Time
        BETWEEN '$Time1' AND '$Time2';";

$result = mysql_query($sqlquery2) or die(mysql_error());
$answer= mysql_fetch_array($result);
extract ($answer);
echo "Total bytes: $answer.";

 
Old March 7th, 2005, 03:20 PM
Authorized User
 
Join Date: Jan 2005
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

here $answer is an array. this is what you need to do:

$sqlquery2 = "SELECT SUM(Bytes) as t_bytes
                FROM test
                WHERE Time
        BETWEEN '$Time1' AND '$Time2';";

$result = mysql_query($sqlquery2) or die(mysql_error());
while($answer= mysql_fetch_array($result)){
      echo $answer['t_bytes'];
}

----------------
Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq
 
Old March 8th, 2005, 12:49 PM
nav nav is offline
Registered User
 
Join Date: Aug 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much for your help Gotaka4.

The answer to the query displays now.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying query from three tables slims07 .NET Framework 2.0 8 April 2nd, 2008 10:47 AM
Displaying web page content in different language vidhyap ASP.NET 2.0 Professional 0 March 13th, 2008 06:46 AM
Displaying textarea content to html table keithc Pro PHP 2 December 1st, 2006 03:12 AM
displaying the query lanita PHP How-To 6 August 23rd, 2004 11:11 PM
data from query not displaying -Dman100- Classic ASP Professional 8 July 19th, 2004 02:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.