PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 19, 2022

[FIXED] How to show number of registered users in Laravel based on usertype?

 October 19, 2022     admin, database, laravel, mysql, php     No comments   

Issue

i'm trying to display data from the database in the admin dashboard

i used this:

            <?php
            use Illuminate\Support\Facades\DB;
            $users = DB::table('users')->count();
            echo $users;
            ?>

and i have successfully get the correct data from the database

but what if i want to display a specific data

for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype

i tried this:

<?php
            use Illuminate\Support\Facades\DB;
            $users = DB::table('users')->count()->WHERE usertype =admin;
            echo $users;
            ?>

but it didn't work, what am i doing wrong?


Solution

you have the wrong syntax. Please read docs carefully...Btw here is the code that you can try

use Illuminate\Support\Facades\DB;

        $users = DB::table('users')->where('usertype','admin')->count();
        echo $users;
        ?>

and for working in the laravel see the usage of Model which will be better for you..



Answered By - Tanvir Ahmed
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing