Show number of user records in table

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
User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Show number of user records in table

Post by bruceholt » 2020-07-28 03:05

I have been trying to show the number of records in a users table but seem to be getting nowhere! If I use:

Code: Select all

<?php echo sqlValue("select count(1) from animals"); ?>
it shows the total number of records in the table but I need to only show the number of records in the table for the logged in user.

I have tried:

Code: Select all

<?php echo sqlvalue("select count(1) from animals left join membership_userrecords on pkValue=animals.id WHERE memberID='".getLoggedMemberID()."'"); ?>
but that isn't correct either>

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

Re: Show number of user records in table

Post by jsetzer » 2020-07-28 07:30

Code: Select all

$tn = "TABLENAME";
$count = sqlValue("SELECT count(*) FROM " . get_sql_from($tn, false, true));
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

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Show number of user records in table

Post by bruceholt » 2020-07-28 07:50

Thanks Jan, How do I place that in the php echo statement?

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

Re: Show number of user records in table

Post by jsetzer » 2020-07-28 09:39

Code: Select all

<?php
$tn = "TABLENAME";
$count = sqlValue("SELECT count(*) FROM " . get_sql_from($tn, false, true));
echo $count;
?>
or

Code: Select all

<?php echo sqlValue("SELECT count(*) FROM " . get_sql_from('TABLENAME', false, true)); ?>

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

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Show number of user records in table

Post by bruceholt » 2020-07-28 10:05

Terrific! Thanks Jan. Worked perfectly.

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

SOLVED: Show number of user records in table

Post by jsetzer » 2020-07-28 10:14

Great, thanks for the feedback!
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

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Show number of user records in table

Post by bruceholt » 2020-07-28 22:18

Hi Jan,

Sorry to bother you again. Wondering how to expand that a bit so that it can show records based on whether a field is NULL or NOT NULL.

I have tried a few different ways but it keeps throwing errors!

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

Re: Show number of user records in table

Post by jsetzer » 2020-07-29 02:31

Code: Select all

<?php
$tn = "TABLENAME";
$count = sqlValue("SELECT count(*) FROM " . get_sql_from($tn, false, true) . " AND `field1` IS NULL AND `field2` IS NOT NULL");
echo $count;
?>
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

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Show number of user records in table

Post by bruceholt » 2020-07-29 03:07

You've done it again! Works great. I really appreciate your help.
Probably helpful for others as well.

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

SOLVED: Show number of user records in table

Post by jsetzer » 2020-07-29 03:41

No prob, have a nice day!
Regards,
Jan
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

Post Reply