CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Need help getting return Value of sum() function in MySQL

Print topic Send  topic

Author Message
JRC
Posted: 11/04/2004, 5:47 AM

$db = new clsDBConnection1 ();
$SQL = "select sum(misfills) from cast_scrap where cast_scrap.date > 2004-08-03";
$temp = $db->query($SQL);
$NewRecord1->s_test->SetValue($temp);
$db->close();

This returns a value of Resource id#10, I have read in other postings this is normal and that you should then use somthing like

db$->f(fieldname); But how do I do this with I am using the sum command?

I am trying to sum totals and then display them in text boxes, any help you can give would be appreciated!
greg
Posted: 11/04/2004, 7:51 AM

You better use CCDLookUp($field_name, $table_name, $where_condition,
&$db) which returns the first value of the result.

If you need more values in a single query, use your code mofified as such:

$SQL = "select sum(misfills) AS MYSUM from...

so you can fetch the value with f('MYSUM').

Greg

JRC wrote:
> $db = new clsDBConnection1 ();
> $SQL = "select sum(misfills) from cast_scrap where cast_scrap.date >
> 2004-08-03";
> $temp = $db->query($SQL);
> $NewRecord1->s_test->SetValue($temp);
> $db->close();
>
> This returns a value of Resource id#10, I have read in other postings this is
> normal and that you should then use somthing like
>
> db$->f(fieldname); But how do I do this with I am using the sum command?
>
> I am trying to sum totals and then display them in text boxes, any help you can
> give would be appreciated!
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
JRC
Posted: 11/04/2004, 8:22 AM

$db = new clsDBConnection1 ();
$SQL = "select sum(misfills) as MYSUM from cast_scrap where cast_scrap.date > 2004-08-03";
$db->query($SQL);
$temp = $db->f("MYSUM");
echo $temp;
$NewRecord1->s_test->SetValue($temp);
$db->close();

Is this what you mean? I tried it but it did not return a value.
mrachow


Posts: 509
Posted: 11/04/2004, 9:40 AM

Despite possible other things
you have to say one time
$db->next_record();
(even for the first one).

In addition this returns a boolean by that you can check if the query was successful and had returned at least one record.

Regards,
Michael
_________________
Best regards,
Michael
View profile  Send private message
JRC
Posted: 11/04/2004, 11:20 AM

It worked! Thanx I just added the $db->next_record(); and it now displays the sum total.

I am just starting out in PHP (used to ASP with VB Script) and I hate doing things by rote. I assume that next_record is a php function and not a codecharge?

Why is that required since it is not a recordset set but a total that the database spits out. If I run that same query right from inside the db it comes back ok?

Thanx again for the help!
mrachow


Posts: 509
Posted: 11/05/2004, 1:12 AM

Yes, next_record is php.

I think all results from queries are stored into record sets. It doesn't matter who the resulting values are achieved.

To be more "close" to Studio try
$db = new clsDBConnection1 (); // Or reuse existing by global
$mySum = CCDLookUp("sum(misfills)", "cast_scrap", "cast_scrap.date > 2004-08-03", $db);

Regards,
Michael
_________________
Best regards,
Michael
View profile  Send private message
JRC
Posted: 11/08/2004, 6:46 AM

Thanx again for the help! Greatly appreciated. Have you had any luck trying to pass a text boxes value to another page. I can do it with DB fields no problem but I will be damed if I can figure out how to do it for just plain old text value from a text box?
peterr


Posts: 5971
Posted: 11/08/2004, 11:30 PM

You would need to retrieve the value of the textbox and pass it to the next page as a URL parameter. The "Multi-Step User Registration" example in CCS Example Pack illustrates how to pass values to the next page.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
JRC
Posted: 11/09/2004, 7:29 AM

Maybe I just don't get it, I have been trying for 2 hours and I think that I am getting further behind :-) I have tried putting in custom code in several places. One is Before unload using the global variable $Redirect and setting it to $Redirect = "?date_from=".urlencode($Main->s_date_from->GetValue()); But it doesn't work the page won't load. I would like to use a button but in code charge it doesn't seem that you can ues them for anything more than update,delete,insert into a DB. I just want the user to enter a two dates and a job number. Then have them click a button/link to open up a report page than uses those three varibles to perform a sql query and build a report. I just can't get the url to pass the varibles. I have done this in other apps in code charge but they have always been passing DB data. Am I making tis harder than it should be?
peterr


Posts: 5971
Posted: 11/09/2004, 12:40 PM

I suspect that the page is not loading because you don't have an If statement to check if a value exists, so your page is redirected somewhere (or nowhere) all the time. Secondly, you're redirecting your page nowhere, because this is an invalid URL: "?date_from=...".

But if you don't need to submit any values to the database (which I didn't know earlier), then as you mentioned you don't even need to use any CCS features, just standard JavaScript. Forget about CCS for a minute and write your own HTML/JavaScript that does what you need. Then modify the HTML page in CCS the same way as it would work without CCS. You can even visit other forums or find on Google how to implement a button that will do what you need with HTML, without CCS. Now that you described more details, I think that a better example for you may be this one: http://examples.codecharge.com/ExamplePack/PopUpList/PopUpList.php
The "Employees List" link on that page passes the value of the "Manager" textbox to another page, just like you described. CCS doesn't need to be used for this - just standard HTML and JavaScript on CCS page.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
andrew
Posted: 11/13/2004, 3:32 PM

im having problems to, i cant display the SUM, and i dont get the code above, here is what i have

echo "<strong>Admin Profits:</strong> ";
$mysql_result = mysql_query("SELECT SUM(adminprofits) AS MYSUM FROM sales");
echo "$mysql_result<br /><br />";

thanks :)
andrew
Posted: 11/13/2004, 3:33 PM

my return value is

Admin Profits: Resource id #7

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.