Display Count of DB Records in PHP Dashboard - php

I need to display a "count" of records (rows) in my SQLtable "doctors". This count must appear on my dashboard page in the below element for total number of doctors
This is index.php for my dashboard page
<?php
$con = mysqli_connect("localhost","root","","hospital_db");
$result = mysqli_query($con,"SELECT * FROM doctors");
$rows = mysqli_num_rows($result);
$content = '<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-aqua">
<div class="inner">
<h3><?php echo '.$rows.';?></h3>
<p>Doctors</p>
</div>
<div class="icon">
<i class="ion ion-bag"></i>
</div>
View Doctors <i class="fa fa-arrow-circle-right"></i>
</div>
</div>
<!-- ./col -->
</div>';
include('../master.php');
?>

You should use mysqli object in new php version try the following code
Make connection first like
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
$result = mysqli_query($con,"SELECT * FROM doctors");
$rows = mysqli_num_rows($result);
echo "There are " . $rows . " rows in my table.";
$content = '<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-aqua">
<div class="inner">
*<h3><?php echo "$rows"; } ?></h3>*
<p>Doctors</p>
</div>
<div class="icon">
<i class="ion ion-bag"></i>
</div>
View Doctors <i class="fa fa-arrow-circle-right"></i>
</div>
</div>
<!-- ./col -->
</div>';
include('../master.php');
?>

if you just need the count then why don't you use the aggregate function count(*) in your query. this much better helps you. and in your code in h3 tag you can concat the string directly rather than using again php code. this might looks better and in structured form.
try this:
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
$result = mysqli_query($con,"SELECT count(*) as total_rows FROM doctors");
$rows = $result->total_rows;
echo "There are " . $rows . " rows in my table.";
$content = '<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-aqua">
<div class="inner">
*<h3>'.$rows.'</h3>*
<p>Doctors</p>
</div>
<div class="icon">
<i class="ion ion-bag"></i>
</div>
View Doctors <i class="fa fa-arrow-circle-right"></i>
</div>
</div>
<!-- ./col -->
</div>';
include('../master.php');
?>

Related

small boxes go out line of container

enter image description here
I'm trying to make a dashboard
When placing small boxes in the board
The boxes that are in the new row go outside the bounds of the page
The boxes in the first row appear correctly, but the problem starts when they go down to the second and third row, and so on.....
How can I solve this problem please?`
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-hc">
<div class="inner text-hc">
<?php
$stmt = $conn->prepare("SELECT * FROM ticket_prices ");
$stmt->execute();
$total = 0;
foreach ($stmt as $srow) {
$subtotal = $srow['TicketPrice'];
$total += $subtotal;
}
echo "<h3>" . $total, 2 . " AED</h3>";
?>
<p>Total Sales from products</p>
</div>
<div class="icon">
<i class="fa fa-shopping-cart"></i>
</div>
<a href="../booking/index.php" class="small-box-footer">More info <i
class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-hc">
<div class="inner text-hc">
<?php
$stmt = $conn->prepare("SELECT * FROM ticket_prices ");
$stmt->execute();
$total = 0;
foreach ($stmt as $srow) {
$subtotal = $srow['TicketPrice'];
$total += $subtotal;
}
echo "<h3>" . $total, 2 . " AED</h3>";
?>
<p>Total Sales from products</p>
</div>
<div class="icon">
<i class="fa fa-shopping-cart"></i>
</div>
<a href="../booking/index.php" class="small-box-footer">More info <i
class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-hc">
<div class="inner text-hc">
<?php
$stmt = $conn->prepare("SELECT * FROM ticket_prices ");
$stmt->execute();
$total = 0;
foreach ($stmt as $srow) {
$subtotal = $srow['TicketPrice'];
$total += $subtotal;
}
echo "<h3>" . $total, 2 . " AED</h3>";
?>
<p>Total Sales from products</p>
</div>
<div class="icon">
<i class="fa fa-shopping-cart"></i>
</div>
<a href="../booking/index.php" class="small-box-footer">More info <i
class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-hc">
<div class="inner text-hc">
<?php
$stmt = $conn->prepare("SELECT * FROM ticket_prices ");
$stmt->execute();
$total = 0;
foreach ($stmt as $srow) {
$subtotal = $srow['TicketPrice'];
$total += $subtotal;
}
echo "<h3>" . $total, 2 . " AED</h3>";
?>
<p>Total Sales from products</p>
</div>
<div class="icon">
<i class="fa fa-shopping-cart"></i>
</div>
<a href="../booking/index.php" class="small-box-footer">More info <i
class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-hc">
<div class="inner text-hc">
<?php
$stmt = $conn->prepare("SELECT * FROM ticket_prices ");
$stmt->execute();
$total = 0;
foreach ($stmt as $srow) {
$subtotal = $srow['TicketPrice'];
$total += $subtotal;
}
echo "<h3>" . $total, 2 . " AED</h3>";
?>
<p>Total Sales from products</p>
</div>
<div class="icon">
<i class="fa fa-shopping-cart"></i>
</div>
<a href="../booking/index.php" class="small-box-footer">More info <i
class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
</section>`
Your HTML structure is wrong. You can see it clearly in sublime or vs code or any of the html editor.
Assuming that you are going to Loop either the 'Box' or the 'Row of 4 Boxes', I have re-structured the HTML without the "PHP" code.
Looping Option 1 :
Look for <!-- Looping Option 1 -->, You can loop the boxes from here.
Looping Option 2 :
Look for <!-- Looping Option 2 -->, You can loop the row of 4 boxes from here.
<section>
<div class="container">
<!-- Lopping option 2 -->
<div class="row">
<!-- Lopping option 1 -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-hc">
<div class="inner text-hc">
<h3></h3>
<p>Total Sales from products</p>
</div>
<div class="icon">
<i class="fa fa-shopping-cart"></i>
</div>
<a href="../booking/index.php" class="small-box-footer">More info <i
class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- Lopping option 1 -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-hc">
<div class="inner text-hc">
<h3></h3>
<p>Total Sales from products</p>
</div>
<div class="icon">
<i class="fa fa-shopping-cart"></i>
</div>
<a href="../booking/index.php" class="small-box-footer">More info <i
class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-hc">
<div class="inner text-hc">
<h3></h3>
<p>Total Sales from products</p>
</div>
<div class="icon">
<i class="fa fa-shopping-cart"></i>
</div>
<a href="../booking/index.php" class="small-box-footer">More info <i
class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-hc">
<div class="inner text-hc">
<h3></h3>
<p>Total Sales from products</p>
</div>
<div class="icon">
<i class="fa fa-shopping-cart"></i>
</div>
<a href="../booking/index.php" class="small-box-footer">More info <i
class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
</div>
<!-- Lopping option 2 -->
</div>
</section>

Add Another Card to the Right PHP SQL

How can i add another user to its right, when i limit it to 5 it goes down not to the right im pretty stuck here how can i align it, i dont know the term or what you call that thing thanks in advance
<h2>Recently Added</h2>
<?php
include_once('connection.php');
$sql = "SELECT * FROM tblstdpro
ORDER BY StdID DESC LIMIT 0, 5";
$result = mysqli_query($conn,$sql);
$count = 0;
while($row = mysqli_fetch_array($result)){
$StudentID="<a href='ProfileRecords.php?id=".$row['StdID']."'>".$row['StdID']."</a>";
$StdName="<a href='ProfileRecords.php?id=".$row['StdID']."'>" . $row['Fname'] . ' ' . $row['Lname'] . "</a>";
?>
<div class="col-md-6">
<!-- USERS LIST -->
<div class="box box-danger">
<div class="box-header with-border">
<h3 class="box-title">Latest Members</h3>
<div class="box-tools pull-right">
<span class="label label-danger"> New Members</span>
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
<button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div><!-- /.box-header -->
<div class="box-body no-padding">
<ul class="users-list clearfix">
<li>
<img src="<?php echo $row['StdImage'];?>" alt="User Image">
<a class="users-list-name" href="#"><?php echo "$StdName" ?></a>
<span class="users-list-date"><?php echo "$StudentID" ?></span>
<?php } ?>
<div class="box-footer text-center">
View All Users
</div><!-- /.box-footer -->
</div><!--/.box -->
</div><!-- /.col -->
</div><!-- /.row -->

Printing out results inside 2 whiles

So im building a fast food website i have built most of it apart from displaying the menu this will be different for each take away which is signed up. I have worked out that im gonna have categories and items so the take away can have a categories called "trays" then 5 items inside that categories with all the different trays they do then they can make another categorie for another block of food and so on. Problem i have is i will need to print out the categories and the items. I have 1 table called categories then another called topics the items will be stored in the topic table and categories in categories so would need to display it like so
categorie
topic
topic
topic
over and over.
Here is my html
<div class="menu-widget" id="2">
<div class="widget-heading">
<h3 class="widget-title text-dark">
POPULAR ORDERS Delicious hot food!
<a class="btn btn-link pull-right" data-toggle="collapse" href="#popular2" aria-expanded="true">
<i class="fa fa-angle-right pull-right"></i>
<i class="fa fa-angle-down pull-right"></i>
</a>
</h3>
<div class="clearfix"></div>
</div>
<div class="collapse in" id="popular2">
<div class="food-item">
<div class="row">
<div class="col-xs-12 col-sm-12 col-lg-8">
<div class="rest-logo pull-left">
<a class="restaurant-logo pull-left" href="#"><img src="http://placehold.it/100x80" alt="Food logo"></a>
</div>
<!-- end:Logo -->
<?php echo "food inside";?>
<div class="rest-descr">
<h6>Veg Extravaganza</h6>
<p> Burgers, American, Sandwiches, Fast Food, BBQ</p>
</div>
<!-- end:Description -->
</div>
<!-- end:col -->
<div class="col-xs-12 col-sm-12 col-lg-4 pull-right item-cart-info"> <span class="price pull-left">$ 19.99</span> + </div>
</div>
<!-- end:row -->
</div>
<!-- end:Food item --><!-- end:Food item --><!-- end:Food item -->
<div class="food-item white"><!-- end:row -->
</div>
<!-- end:Food item -->
</div>
<!-- end:Collapse -->
</div>
<!-- end:Widget menu -->
and here is my code
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-6"><!-- end:Widget menu -->
<?php
///first select the category based on $_GET['cat_id']
$sql = "SELECT * FROM categories WHERE takeawayid =' ".$id1."'";
$result = mysql_query($sql);
if(!$result)
{
echo 'The category could not be displayed, please try again later.' . mysql_error();
}
else
{
if(mysql_num_rows($result) == 0)
{
echo 'This category does not exist.';
}
else
{
//display category data
while($row = mysql_fetch_assoc($result))
{
?>
<div class="menu-widget" id="2">
<div class="widget-heading">
<h3 class="widget-title text-dark">
<?php echo $row['cat_name'] ; ?> <a class="btn btn-link pull-right" data-toggle="collapse" href="#popular2" aria-expanded="true">
<i class="fa fa-angle-right pull-right"></i>
<i class="fa fa-angle-down pull-right"></i>
</a>
</h3>
<div class="clearfix"></div>
<?php
//do a query for the topics
$sql2 = "SELECT * FROM topics WHERE topic_cat =' ".$row['cat_id']."'";
$result2 = mysql_query($sql2);
}
echo $row2['topic_subject'] ;
if(!$result2)
{
echo 'The topics could not be displayed, please try again later.';
}
else
{
if(mysql_num_rows($result2) == 0)
{
echo 'There are no topics in this category yet.';
}
else
{
//prepare the table
while($row2 = mysql_fetch_assoc($result2))
{
?>
<div class="collapse in" id="popular2">
<div class="food-item">
<div class="row">
<div class="col-xs-12 col-sm-12 col-lg-8">
<div class="rest-logo pull-left">
<a class="restaurant-logo pull-left" href="#"><img src="http://sdfsdf.com/beta/restaurants/<?php echo $id33 ;?>.png" alt="Food logo"></a>
</div>
<!-- end:Logo -->
<div class="rest-descr">
<h6><?php echo $row2['topic_subject'] ;?></h6>
<p> Burgers, American, Sandwiches, Fast Food, BBQ</p>
</div>
<!-- end:Description -->
</div>
<!-- end:col -->
<div class="col-xs-12 col-sm-12 col-lg-4 pull-right item-cart-info"> <span class="price pull-left">$ 19.99</span> + </div>
</div>
<!-- end:row -->
</div>
<!-- end:Food item --><!-- end:Food item --><!-- end:Food item -->
<div class="food-item white"><!-- end:row -->
</div>
<!-- end:Food item -->
</div>
<!-- end:Collapse -->
</div>
</div>
<?php
}
}
}
}
}
?>
<!-- end:Widget menu -->
Code works but when i add more than 1 result im getting this
http://prntscr.com/fu3qll
Here is 1 cat and 2 topics in side it
https://prnt.sc/fu3g2j
works great but when i add 2 cats and 4 topics 2 inside each one i get above the fu3kbk link
so i fixed it by moving the bracket down on
$result2 = mysql_query($sql2);
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-6"><!-- end:Widget menu -->
<?php
///first select the category based on $_GET['cat_id']
$sql = "SELECT * FROM categories WHERE takeawayid =' ".$id1."'";
$result = mysql_query($sql);
if(!$result)
{
echo 'The category could not be displayed, please try again later.' . mysql_error();
}
else
{
if(mysql_num_rows($result) == 0)
{
echo 'This category does not exist.';
}
else
{
//display category data
while($row = mysql_fetch_assoc($result))
{
?>
<div class="menu-widget" id="2">
<div class="widget-heading">
<h3 class="widget-title text-dark">
<?php echo $row['cat_name'] ; ?> <a class="btn btn-link pull-right" data-toggle="collapse" href="#popular2" aria-expanded="true">
<i class="fa fa-angle-right pull-right"></i>
<i class="fa fa-angle-down pull-right"></i>
</a>
</h3>
<div class="clearfix"></div>
</div>
<?php
//do a query for the topics
$sql2 = "SELECT * FROM topics WHERE topic_cat =' ".$row['cat_id']."'";
$result2 = mysql_query($sql2);
if(!$result2)
{
echo 'The topics could not be displayed, please try again later.';
}
else
{
if(mysql_num_rows($result2) == 0)
{
echo 'There are no topics in this category yet.';
}
else
{
//prepare the table
while($row2 = mysql_fetch_assoc($result2))
{
?>
<div class="collapse in" id="popular2">
<div class="food-item">
<div class="row">
<div class="col-xs-12 col-sm-12 col-lg-8">
<div class="rest-logo pull-left">
<a class="restaurant-logo pull-left" href="#"><img src="http://geatzo.com/beta/restaurants/<?php echo $id33 ;?>.png" alt="Food logo"></a>
</div>
<!-- end:Logo -->
<div class="rest-descr">
<h6><?php echo $row2['topic_subject'] ;?></h6>
<p> Burgers, American, Sandwiches, Fast Food, BBQ</p>
</div>
<!-- end:Description -->
</div>
<!-- end:col -->
<div class="col-xs-12 col-sm-12 col-lg-4 pull-right item-cart-info"> <span class="price pull-left">$ 0</span> + </div>
</div>
<!-- end:row -->
</div>
<!-- end:Food item --><!-- end:Food item --><!-- end:Food item -->
<!-- end:Food item -->
</div>
<!-- end:Collapse -->
<?php
}
}
}
}
}
}
?>
</div>
</div>
<!-- end:Widget menu -->

Codeigniter : Refreshing home after log in increments objects

I have a strange thing in my web application. I have a log in form. When I log in I get my users page with a field. That field contains the amount of projects are running on my account. It's just a SQL query with a result etc..
When I log in I get the data I need.. 0. Because it's just a new user. My url on that moment is :
http://www.xxxxx.be/yyyyyy/index.php/User/login
When I refresh the page. My amount of projects got +1. So 1 now..
I think it's something about parameters etc..
This is the controllers function of my login:
public function login() {
$loggedin = $this->session->userdata('user_id');
if (!$loggedin) {
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('user_mail', 'user mail', 'required');
$this->form_validation->set_rules('user_password', 'user password', 'required');
if ($this->form_validation->run() == false) {
$data = new stdClass();
$data->error = 'Check your user and password';
$this->load->view('dashboard_login', $data);
} else {
$usermail = $this->input->post('user_mail');
$password = $this->input->post('user_password');
if ($this->user_model->resolve_user_login($usermail, $password)) {
$user_id = $this->user_model->get_user_id_from_mail($usermail);
$user = $this->user_model->get_user($user_id);
$this->session->set_userdata('user_id', $user_id);
$this->session->set_userdata('user_name', (string) $user->user_name);
$this->session->set_userdata('user_gsm', (string) $user->user_gsm);
$this->session->set_userdata('user_address', (string) $user->user_address);
$this->session->set_userdata('user_city', (string) $user->user_city);
$this->session->set_userdata('userlevel', $this->user_model->get_user_level((int) $user->user_id));
$this->session->set_userdata('user_mail', $usermail);
$data['userdata'] = $this->session->userdata;
if ($this->session->userdata('userlevel') == "3") {
$data['employeetotal'] = $this->user_model->get_amount_employees();
$data['customertotal'] = $this->user_model->get_amount_customers();
$data['projectstotal'] = $this->user_model->get_amount_projects();
} else {
$data['projectstotal'] = $this->user_model->get_amount_projects_from_user($this->session->userdata('user_id'));
}
$data['userdata'] = $this->session->userdata;
$this->load->view('header', $data);
$this->load->view('dashboard_index', $data);
$this->load->view('wrapper', $data);
} else {
$data = new stdClass();
// login failed
$data->error = 'Wrong username or password.';
// send error to the view
$this->load->view('dashboard_login', $data);
}
}
} else {
$data['userdata'] = $this->session->userdata;
$data['employeetotal'] = $this->user_model->get_amount_employees();
$data['customertotal'] = $this->user_model->get_amount_customers();
$data['projectstotal'] = $this->user_model->get_amount_projects();
$this->load->view('header', $data);
$this->load->view('dashboard_index', $data);
$this->load->view('wrapper', $data);
}
}
The specific user has userlevel 1. So executes model function:
$data['projectstotal'] = $this->user_model->get_amount_projects_from_user($this->session->userdata('user_id'));
This is the code from that function:
function get_amount_projects_from_user($userid) {
$sql = "select count(project_id) as aantal from tbl_user_project where user_id = $userid";
$query = $this->db->query($sql);
$result = $query->result();
return $result;
}
The index pages looks like:
<?php if ($userdata['userlevel'] == "3") { ?>
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-yellow">
<div class="inner">
<h3><?php echo $customertotal[0]->aantal; ?></h3>
<p>Customers</p>
</div>
<div class="icon">
<a href="<?= site_url('User/redirect_register') ?>"<i class="ion ion-person-add" ></i></a>
</div>
Add<i class="fa fa-arrow-circle-right"></i>
</div>
</div>
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-aqua">
<div class="inner">
<h3><?php echo $projectstotal[0]->aantal; ?></h3>
<p>Projects</p>
</div>
<div class="icon">
<i class="ion ion-bag"></i>
</div>
More info<i class="fa fa-arrow-circle-right"></i>
</div>
</div>
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-green">
<div class="inner">
<h3><?php echo $employeetotal[0]->aantal; ?></h3>
<p>Employees</p>
</div>
<div class="icon">
<i class="ion ion-stats-bars"></i>
</div>
Add<i class="fa fa-arrow-circle-right"></i>
</div>
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-red">
<div class="inner">
<h3>65</h3>
<p>Unique Visitors</p>
</div>
<div class="icon">
<i class="ion ion-pie-graph"></i>
</div>
<a href="#" class="small-box-footer">
More info <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div><!-- ./col -->
</div>
<div class="row">
<!-- /.col -->
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="info-box bg-yellow">
<span class="info-box-icon"><i class="fa fa-calendar"></i></span>
<div class="info-box-content">
<span class="info-box-text">Events</span>
<span class="info-box-number">41,410</span>
<div class="progress">
<div class="progress-bar" style="width: 70%"></div>
</div>
<span class="progress-description">
70% Increase in 30 Days
</span>
</div><!-- /.info-box-content -->
</div><!-- /.info-box -->
</div><!-- /.col -->
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="info-box bg-aqua">
<span class="info-box-icon"><i class="fa fa-bookmark-o"></i></span>
<div class="info-box-content">
<span class="info-box-text">Running projects</span>
<span class="info-box-number">3</span>
<div class="progress">
<div class="progress-bar" style="width: 70%"></div>
</div>
<span class="progress-description">
70% Increase last 10 Days
</span>
</div><!-- /.info-box-content -->
</div><!-- /.info-box -->
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="info-box bg-green">
<span class="info-box-icon"><i class="fa fa-thumbs-o-up"></i></span>
<div class="info-box-content">
<span class="info-box-text">Likes</span>
<span class="info-box-number">510</span>
<div class="progress">
<div class="progress-bar" style="width: 20%"></div>
</div>
<span class="progress-description">
70% Increase in 30 Days
</span>
</div><!-- /.info-box-content -->
</div><!-- /.info-box -->
</div><!-- /.col -->
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="info-box">
<span class="info-box-icon bg-red"><i class="fa fa-google-plus"></i></span>
<div class="info-box-content">
<span class="info-box-text">Likes</span>
<span class="info-box-number">80</span>
</div><!-- /.info-box-content -->
</div><!-- /.info-box -->
</div>
</div>
</h1>
</div><!-- /.content-wrapper -->
<?php } else { ?>
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-aqua">
<div class="inner">
<h3><?php echo $projectstotal[0]->aantal; ?></h3>
<p>Projects</p>
</div>
<div class="icon">
<i class="ion ion-bag"></i>
</div>
More info<i class="fa fa-arrow-circle-right"></i>
</div>
</div>
</h1>
</div><!-- /.content-wrapper -->
<?php } ?>
Try checking the result of your get_amount_projects_from_user($userid) method.I think $query->result() returns an array of result, so you can get the count of your project by looping trough the result
Check this example:
$sql = "select count(project_id) as aantal from tbl_user_project where user_id = $userid";
$query = $this->db->query($sql);
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
echo $row->aantal;
}
}
in your case, I think you should use the $query->row() since we are sure that we only need one result.
$sql = "select count(project_id) as aantal from tbl_user_project where user_id = $userid";
$query = $this->db->query($sql);
if ($query->num_rows() > 0)
{
$row = $query->row();
return $row->aantal;
}
I hope this has given you some idea.
Here is a link that I think is usefull:

Bootstrap columns not working when writing in php while loop

I am using bootstrap in my website but when i am adding php loop to show the products the products are shown at the end of the page instead of showing in the area 'product will show here'.
<div class="col-sm-9 padding-right">
<div class="features_items">
<h2 class="title text-center">Features Items</h2>
<?php
function fetch($table){
$result = mysqli_query($conn,"SELECT id ,name FROM menshirt");
while($row = mysqli_fetch_assoc($result)) {
echo
'<div class="col-sm-4">
<h2>$56</h2>
p> '.$name =$row['name'].'</p>
<i class="fa fa-cart"> </i>Add to cart
</div>
</div>';
}
mysqli_close($conn);}
?>
</div></div>
You only creates a function fetch which isn't called. And inside open less divs than closed.
<div class="col-sm-9 padding-right">
<div class="features_items">
<h2 class="title text-center">Features Items</h2>
<?php
$result = mysqli_query($conn,"SELECT id ,name FROM menshirt");
while($row = mysqli_fetch_assoc($result)) {
echo '
<div class="col-sm-4">
<h2>$56</h2>
p> '. $row['name'] . '</p>
<i class="fa fa-cart"> </i>Add to cart
</div>
<!--/div--> <!-- you opened one div, tried to close two -->
';
}
mysqli_close($conn);}
?>
</div>
</div>

Categories