Custom Page - Column Sum

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
jangle
Veteran Member
Posts: 89
Joined: 2020-01-18 17:41

Custom Page - Column Sum

Post by jangle » 2020-10-08 17:38

Hello Forum,

I am trying to echo the sum of a column from Mysql DB on a custom PHP page. The DB connection seems to work ok, but I get a Call to undefined function mysql_query() in C:\xampp\htdocs\COVID-19\hooks\COVIDReports.php:19 error when loading the page.

Anything look wrong????

Thanks in advance.

Jim

Code: Select all

<?php
    $servername = "localhost";
    $database = "serp";
    $username = "root";
    $password =  "";
    
    // Create connection
    
    $conn = mysqli_connect($servername, $username, $password, $database);
    
    // Check connection
    
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }    
    echo 'Connected successfully';
    
    
    $result= mysql_query("SELECT SUM(workforce_out) AS totalsum FROM workforce_impact_report_30_days");
    $row = mysql_fetch_assoc($result); 

    $sum = $row['totalsum'];

    echo ("This is the sum: $sum");

    
    mysqli_close($conn); 

    
    
    ?>

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Custom Page - Column Sum

Post by jsetzer » 2020-10-08 18:20

I recommend using the AppGini built in sql-function if you fetch data from current database.

Are you sure you mean mysql_* functions?
I guess you will have to use mysqli_* functions instead.
I think you have mixed up mysqli-functons and mysql-functions.

Can you please ask your questions in the forum, not as private message to me, then, also other users can help you. Thanks.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

jangle
Veteran Member
Posts: 89
Joined: 2020-01-18 17:41

Re: Custom Page - Column Sum

Post by jangle » 2020-10-08 19:48

I did post this in the forum..... I did sent you a PM with regard to a comment the you sent to me. Did you get that?

jangle
Veteran Member
Posts: 89
Joined: 2020-01-18 17:41

Re: Custom Page - Column Sum

Post by jangle » 2020-10-08 19:50

Thanks

Can you give me an example of how to use this "AppGini built in sql-function"?

Thanks

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Custom Page - Column Sum

Post by jsetzer » 2020-10-08 20:19

I must have missed that, sorry!!!
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

jangle
Veteran Member
Posts: 89
Joined: 2020-01-18 17:41

Re: Custom Page - Column Sum

Post by jangle » 2020-10-08 21:52

Copy just wanted to make sure you got it.

Can you give me an example of the built in appgini function that you mention.

Thanks

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Custom Page - Column Sum

Post by jsetzer » 2020-10-09 04:25

Code: Select all

$eo = null;
$rows = [];
$res = sql("select * from TABLENAME", $eo);
if (!$eo) { 
  while($row = db_fetch_assoc($res)) 
    $rows[] = $row;
}
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

jangle
Veteran Member
Posts: 89
Joined: 2020-01-18 17:41

Re: Custom Page - Column Sum

Post by jangle » 2020-10-09 12:57

Thank you very much. I will try out....

jangle
Veteran Member
Posts: 89
Joined: 2020-01-18 17:41

Re: Custom Page - Column Sum

Post by jangle » 2020-10-09 13:10

I am not sure how to make this sum the column and echo the result...?????

Code: Select all

$eo = null;
$rows = [];
$res = sql("select * from TABLENAME", $eo);
if (!$eo) { 
  while($row = db_fetch_assoc($res)) 
    $rows[] = $row;
}

jangle
Veteran Member
Posts: 89
Joined: 2020-01-18 17:41

Re: Custom Page - Column Sum

Post by jangle » 2020-10-09 13:14

I got it with this.... thanks Jan!!!

Code: Select all

  $result = mysqli_query($conn, 'SELECT SUM(workforce_out) AS value_sum FROM workforce_impact_report_30_days'); 
$row = mysqli_fetch_assoc($result); 
$sum = $row['value_sum'];

    
    echo ("This is the sum: $sum"); 

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Custom Page - Column Sum

Post by jsetzer » 2020-10-09 13:17

Well done. I'm wondering if $conn is the same DB or a different datasource.

If this is the same DB, you can also use the built-in sqlValue()-function:

Code: Select all

$sum = sqlValue('SELECT SUM(workforce_out) FROM workforce_impact_report_30_days'); 
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

jangle
Veteran Member
Posts: 89
Joined: 2020-01-18 17:41

Re: Custom Page - Column Sum

Post by jangle » 2020-10-16 02:51

Thanks Jan

It is the same Db connection.

User avatar
landinialejandro
AppGini Super Hero
AppGini Super Hero
Posts: 126
Joined: 2016-03-06 00:59
Location: Argentina
Contact:

Re: Custom Page - Column Sum

Post by landinialejandro » 2020-11-08 15:20

jangle wrote:
2020-10-09 13:10
I am not sure how to make this sum the column and echo the result...?????

Code: Select all

$eo = null;
$rows = [];
$res = sql("select * from TABLENAME", $eo);
if (!$eo) { 
  while($row = db_fetch_assoc($res)) 
    $rows[] = $row;
}
hi folow the next link to help you how to create a custom page.
https://bigprof.com/appgini/help/advanc ... cess-pages
the most importat is the lib.php.

then you can use de sql function.
Just like Jan sai exist the sqlValue function, this fucntion return a only one value.

Code: Select all

$sum = sqlValue('SELECT SUM(workforce_out)  FROM workforce_impact_report_30_days');
echo $sum;
Alejandro.
AppGini 5.98 - Linux OpenSuse Tumblewweed.

Some of my posts that may interest you:
:arrow: Landini Admin Template: Template for Appgini like AdminLTE
:arrow: Profile image plugin: add and changue image user profile
:arrow: Field editor in table view: Configurable fast edit fields in TV
:idea: my personal page

jangle
Veteran Member
Posts: 89
Joined: 2020-01-18 17:41

Re: Custom Page - Column Sum

Post by jangle » 2020-11-20 13:39

Thanks all!!!

Post Reply