Page 1 of 1

Show number of user records in table

Posted: 2020-07-28 03:05
by bruceholt
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>

Re: Show number of user records in table

Posted: 2020-07-28 07:30
by jsetzer

Code: Select all

$tn = "TABLENAME";
$count = sqlValue("SELECT count(*) FROM " . get_sql_from($tn, false, true));

Re: Show number of user records in table

Posted: 2020-07-28 07:50
by bruceholt
Thanks Jan, How do I place that in the php echo statement?

Re: Show number of user records in table

Posted: 2020-07-28 09:39
by jsetzer

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)); ?>


Re: Show number of user records in table

Posted: 2020-07-28 10:05
by bruceholt
Terrific! Thanks Jan. Worked perfectly.

SOLVED: Show number of user records in table

Posted: 2020-07-28 10:14
by jsetzer
Great, thanks for the feedback!

Re: Show number of user records in table

Posted: 2020-07-28 22:18
by bruceholt
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!

Re: Show number of user records in table

Posted: 2020-07-29 02:31
by jsetzer

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;
?>

Re: Show number of user records in table

Posted: 2020-07-29 03:07
by bruceholt
You've done it again! Works great. I really appreciate your help.
Probably helpful for others as well.

SOLVED: Show number of user records in table

Posted: 2020-07-29 03:41
by jsetzer
No prob, have a nice day!
Regards,
Jan