Skip to main content
Topic: Counting records for a dashboard total only for the logged in user (Read 1423 times) previous topic - next topic

Counting records for a dashboard total only for the logged in user

Hello There,

I would like to counting records for a dashboard total only for the logged in user. I try this  "SELECT COUNT(*) AS num FROM hostingpakketten" But the tabel has an username in it so i need to only show the users rows. and not all..

Please help..

Re: Counting records for a dashboard total only for the logged in user

Reply #1
@pvisser‍ please limit it by adding the MySQL where clause to your query.
Example:
Code: [Select]
"SELECT * FROM table WHERE userid =".USER_ID

Re: Counting records for a dashboard total only for the logged in user

Reply #2
Hi There, Thanks but the counter seas 0 even there is one reccord..

I Try this :

"SELECT COUNT(*) AS num FROM hostingpakketten WHERE Naam_Klant=" .USER_ID

PLease advice

Re: Counting records for a dashboard total only for the logged in user

Reply #3
@pvisser‍ is it a user id you store in this field Naam_Klant or a user name? if it is a user id, your query should work, if not it wouldn't work. If it is a user name, please use USER_NAME in place of USER_ID, and also the view helper for functions and variables you can use.

Re: Counting records for a dashboard total only for the logged in user

Reply #4
Hello again. Yes it is the username stored in the field but when I user USER_NAME I see an error 500.  when I use the USER_iD then it stil counts all records instead the records from the user logged in

Please advise

Re: Counting records for a dashboard total only for the logged in user

Reply #5
@pvisser‍ make sure u are not missing the dot before the variable, please look at query properly and the instructions above, thanks.

Re: Counting records for a dashboard total only for the logged in user

Reply #6
I Did like this right?

"SELECT COUNT(*) AS num FROM hostingpakketten WHERE Naam_Klant=" .USER_NAME

This is the Table : hostingpakketten
This is the field in the table te usename is saved in : Naam_Klant

So if PIET is logged in, i only want to count the records with PIET his name in field : Naam_Klant

Please Advice.


 

Re: Counting records for a dashboard total only for the logged in user

Reply #8
Hello there thank you for helping out.  I noticed that I had to use user_id to store in the table instead of use_name then I can query the name in the table.  The only think I would like to know is :

How can I auto fill fields from the user table in a table hostingpacks with a field like eg Customer

In the Table user I have
ID
Username
Password
Role

In the table Hostingpacks  I have :
Username (as (Selectbox) with the list from the table user)
Customer (I want to auto fill with the username if I select a username from the above field from the table user)

Can you please advice me with a sample how to do this? That would be great..

Thank you so mutch.  I love PHPRad.  More than Appgini I own also