Bootstrap 3 dropdown button height and search - php

I'm having a little problem with bootstrap 3. I tried for the whole day to solve and searched everything in internet even used FireBug but didn't help.
The button of dropdown is higher than the menu and its going outside the menu.
<ul class="nav navbar-nav navbar-right">
<?php if(!is_array(session( 'thisUser'))): ?>
<span class="glyphicon glyphicon-user"></span> <?php echo T('Register') ?>
<span class="glyphicon glyphicon-log-in"></span> <?php echo T('Login') ?>
<?php else: ?>
<li class="dropdown">
<a class="dropdown-toggle text-notransform" data-toggle="dropdown" href="#">
<img src="<?php echo URL(session_get('preferences', 'avatar')) ?>" width="24px">
<?php echo session_get('thisUser', 'username') ?> <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<div class="navbar-login">
<div class="row">
<div class="col-lg-4">
<p class="text-center">
<img src="<?php echo URL(session_get('preferences', 'avatar')) ?>" width="200px">
</p>
</div>
<div class="col-lg-8">
<p class="text-left"><strong><?php echo session_get('thisUser', 'username') ?></strong>
</p>
<p class="text-left small">
<?php echo session_get( 'thisUser', 'email') ?>
</p>
<br />
<p class="text-left">
<a href="<?php echo URL(T('setting-slug', 'settings')) ?>" class="btn btn-primary btn-block btn-sm">
<?php echo T( 'Settings') ?>
</a>
<?php echo event( 'user_menu', '') ?>
</p>
</div>
</div>
</div>
</li>
<li class="divider"></li>
<li>
<div class="navbar-login navbar-login-session">
<div class="row">
<div class="col-lg-12">
<p>
<a href="<?php echo URL('logout') ?>" class="btn btn-danger btn-block">
<?php echo T( 'Logout') ?>
</a>
</p>
</div>
</div>
</div>
</li>
</ul>
</li>
</ul>
<?php endif; ?>
</ul>
My second problem is with the bootstrap search I want the button search to be next to the search text not bellow it. The code is PHP function:
function search_box($a){
$return .= Form::open(array('method'=>'GET', 'action'=>URL(T('directory'))));
$return .= Form::input('q', R('q'), array('class'=>'form-control input-md', 'style'=>'margin-bottom:5px','placeholder'=>T('Type smth to search')));
$return .= '<button type="submit" class="btn btn-block btn-md btn-primary"><i class="icon-find"></i> '.T('Search').'</button>';
$return .= Form::close();
$return .= '<div class="clearfix"><br /></div>';
return $return;
}
(For image of the search is the same as the above link)
Can someone tell me how to fix this. Thanks in advance.

On your searchbox($a) function, try removing btn-md class from button.

Related

php ajax multiple insert ı need

<div class="row">
<?php
$sql=mysqli_query($conn,"select * from is_ilanlari");
while($oku=mysqli_fetch_object($sql))
{
?>
<div class="col-md-4">
<aside class="profile-nav alt">
<section class="card">
<div class="card-header user-header alt bg-dark" >
<div class="media">
<a href="#">
<img class="align-self-center rounded-circle mr-3" style="width:100px; height:100px;" alt="" src="images/korucanta.jpg">
</a>
<div class="media-body">
<h2 class="text-light display-6" style="size:10px;"><?php echo $oku->is_ilanlari_baslik; ?></h2>
<p>Görev süresi : <?php echo $oku->is_ilanlari_bekleme_suresi; ?></p>
<div class="h4 mb-0" style="float:right;"></div>
</div>
</div>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<a href="#"> <i class="fa fa-money"></i><b> Para kazancı </b>
<span class="badge badge-primary pull-right"> <?php echo $oku->is_ilanlari_kazanc; ?></span></a>
</li>
<li class="list-group-item">
<a href="#"> <i class="fa fa-plus-circle"></i><b> XP kazancı </b>
<span class="badge badge-danger pull-right"><?php echo $oku->is_ilanlari_bp; ?></span></a>
</li>
<li class="list-group-item">
<a href="#"> <i class="fa fa-clock-o"></i><b> Görev süresi</b>
<span class="badge badge-danger pull-right" style="background-color:#35dccd; height:28px; text-color:white;">
<p id="kutu1"><?php echo number_format($oku->is_ilanlari_bekleme_suresi); ?></p></span></a>
</li>
<li class="list-group-item">
<form method="POST" id="degerler">
<button type="button" name="buton<?php echo $oku->is_ilanlari_id; ?>" value="<?php echo $oku->is_ilanlari_id; ?>" class="btn btn-secondary btn-lg btn-block">KORUMAYA BAŞLA </button>
</form>
<script>
$(document).ready(function() {
$('button').on('click', function() {
$("button").attr("disabled", "disabled");
var is_id = $(this).val();
if(is_id!=""){
$.ajax({
url: "isbaslat.php",
type: "POST",
data: {
is_id: is_id
},
cache: false,
success: function(dataResult){
var dataResult = JSON.parse(dataResult);
if(dataResult.statusCode==1){
//$("button").removeAttr("disabled");
$('#degerler').find('input:text').val('');
$("#success").show();
$('#success').html('İş Başladı !');
console.log("b");
}
else if(dataResult.statusCode==0){
alert("Error occured !");
}
}
});
}
else{
alert('Please fill all the field !');
}
});
});
</script>
</li>
</ul>
</section>
</aside>
</div>
<?php
}
?>
</div>
this is form create php and ajax
can you see ?
<?php
session_start();
include('baglanti.php');
include('fonksiyonlar.php');
$kid=$_SESSION['kullanici_adi'];
getir_kullanici($kid);
$k_id=$getir['kid'];
$is_id=$_POST['is_id'];
$sql = "insert into kullanici_is(is_ilan_id,kullanici_id,is_baslangic_tarih,is_durum)
values ('$is_id','$k_id','".date("Y-m-d H:i:s")."',1)";
if (mysqli_query($conn, $sql)) {
echo json_encode(array("statusCode"=>1));
}
else {
echo json_encode(array("statusCode"=>0));
}
mysqli_close($conn);
?>
this is insert php you can see
http://prntscr.com/rhrmp5
ı want to insert a line.But this buttons all of them click and inserted 8 line in database.
How ı can insert just clicked value.
ı tryed all things pls help me
ı try again but no ı can t do it pls help me ı need more help . ı am waiting for
issue: code inside loop
Solution: move js code outside loop to avoid multiple instances,
use a class for all buttons
$('.btn_class').on('click', function() {
// now only the specific btn is clicked
$(this).val(); // will be of the clicked btn
...
}
add btn class
<form method="POST" id="degerler">
<button type="button" name="buton<?php echo $oku->is_ilanlari_id; ?>" value="<?php echo $oku->is_ilanlari_id; ?>" class="btn btn-secondary btn-lg btn-block btn_class">KORUMAYA BAŞLA </button>
</form>
fixed :
<div class="row">
<?php
$sql=mysqli_query($conn,"select * from is_ilanlari");
while($oku=mysqli_fetch_object($sql))
{
?>
<div class="col-md-4">
<aside class="profile-nav alt">
<section class="card">
<div class="card-header user-header alt bg-dark" >
<div class="media">
<a href="#">
<img class="align-self-center rounded-circle mr-3" style="width:100px; height:100px;" alt="" src="images/korucanta.jpg">
</a>
<div class="media-body">
<h2 class="text-light display-6" style="size:10px;"><?php echo $oku->is_ilanlari_baslik; ?></h2>
<p>Görev süresi : <?php echo $oku->is_ilanlari_bekleme_suresi; ?></p>
<div class="h4 mb-0" style="float:right;"></div>
</div>
</div>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<a href="#"> <i class="fa fa-money"></i><b> Para kazancı </b>
<span class="badge badge-primary pull-right"> <?php echo $oku->is_ilanlari_kazanc; ?></span></a>
</li>
<li class="list-group-item">
<a href="#"> <i class="fa fa-plus-circle"></i><b> XP kazancı </b>
<span class="badge badge-danger pull-right"><?php echo $oku->is_ilanlari_bp; ?></span></a>
</li>
<li class="list-group-item">
<a href="#"> <i class="fa fa-clock-o"></i><b> Görev süresi</b>
<span class="badge badge-danger pull-right" style="background-color:#35dccd; height:28px; text-color:white;">
<p id="kutu1"><?php echo number_format($oku->is_ilanlari_bekleme_suresi); ?></p></span></a>
</li>
<li class="list-group-item">
<form method="POST" id="degerler">
<button type="button" name="buton<?php echo $oku->is_ilanlari_id; ?>" value="<?php echo $oku->is_ilanlari_id; ?>" class="btn btn-secondary btn-lg btn-block">KORUMAYA BAŞLA </button>
</form>
</li>
</ul>
</section>
</aside>
</div>
<?php
}
?>
</div>
// move script outside the loop
<script>
$(document).ready(function() {
$('button').on('click', function() {
$("button").attr("disabled", "disabled");
var is_id = $(this).val();
if(is_id!=""){
$.ajax({
url: "isbaslat.php",
type: "POST",
data: {
is_id: is_id
},
cache: false,
success: function(dataResult){
var dataResult = JSON.parse(dataResult);
if(dataResult.statusCode==1){
//$("button").removeAttr("disabled");
$('#degerler').find('input:text').val('');
$("#success").show();
$('#success').html('İş Başladı !');
console.log("b");
}
else if(dataResult.statusCode==0){
alert("Error occured !");
}
}
});
}
else{
alert('Please fill all the field !');
}
});
});
</script>

I Have Database Errors on my Codeigniter script

i install a school management system and one time login but after logout and enter username and password show a box with this message:
A Database Error Occurred , You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE _id IS NULL' at line 2 . SELECT * WHERE _id IS NULL . Filename: views/backend/header.php . Line Number: 34 "
header.php code :
<div class="row">
<div class="col-md-12 col-sm-12 clearfix" style="text-align:center;">
<h2 style="font-weight:200; margin:0px;"><?php echo $system_name;?></h2>
</div>
<!-- Raw Links -->
<div class="col-md-12 col-sm-12 clearfix ">
<ul class="list-inline links-list pull-left">
<!-- Language Selector -->
<div id="session_static">
<li>
<h4>
<a href="#" style="color: #696969;"
<?php if($account_type == 'admin'):?>
onclick="get_session_changer()"
<?php endif;?>>
<?php echo get_phrase('running_session');?> : <?php echo $running_year.' ';?><i class="entypo-down-dir"></i>
</a>
</h4>
</li>
</div>
</ul>
<ul class="list-inline links-list pull-right">
<li class="dropdown language-selector">
<a href="<?php echo site_url('home');?>" target="_blank">
<i class="entypo-globe"></i> Website
</a>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" data-close-others="true">
<i class="entypo-user"></i>
<?php
$name = $this->db->get_where($this->session->userdata('login_type'), array($this->session->userdata('login_type').'_id' => $this->session->userdata('login_user_id')))->row()->name;
echo $name;
?>
</a>
<?php if ($account_type != 'parent'):?>
<ul class="dropdown-menu <?php if ($text_align == 'right-to-left') echo 'pull-right'; else echo 'pull-left';?>">
<li>
<a href="<?php echo site_url($account_type . '/manage_profile');?>">
<i class="entypo-info"></i>
<span><?php echo get_phrase('edit_profile');?></span>
</a>
</li>
<li>
<a href="<?php echo site_url($account_type . '/manage_profile');?>">
<i class="entypo-key"></i>
<span><?php echo get_phrase('change_password');?></span>
</a>
</li>
</ul>
<?php endif;?>
<?php if ($account_type == 'parent'):?>
<ul class="dropdown-menu <?php if ($text_align == 'right-to-left') echo 'pull-right'; else echo 'pull-left';?>">
<li>
<a href="<?php echo site_url('parents/manage_profile');?>">
<i class="entypo-info"></i>
<span><?php echo get_phrase('edit_profile');?></span>
</a>
</li>
<li>
<a href="<?php echo site_url('parents/manage_profile');?>">
<i class="entypo-key"></i>
<span><?php echo get_phrase('change_password');?></span>
</a>
</li>
</ul>
<?php endif;?>
</li>
<li>
<a href="<?php echo site_url('login/logout');?>">
<?php echo get_phrase('log_out'); ?><i class="entypo-logout right"></i>
</a>
</li>
</ul>
</div>
</div>
<hr style="margin-top:0px;" />
<script type="text/javascript">
function get_session_changer()
{
$.ajax({
url: '<?php echo site_url('admin/get_session_changer');?>',
success: function(response)
{
jQuery('#session_static').html(response);
}
});
}
</script>
line 34 :
$name = $this->db->get_where($this->session->userdata('login_type'), array($this->session->userdata('login_type').'_id' => $this->session->userdata('login_user_id')))->row()->name;
I am beginner . please help me step by step

why this is Invalid argument supplied for foreach()?

I don't understand why, the error says :
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\twitter\core\ajax\popuptweets.php on line 134 , and I don't see any error or maybe I'm blind !!
popuptweets.php code
<?php
include '../init.php';
if (isset($_POST['showpopup']) && !empty($_POST['showpopup'])) {
$tweetID = $_POST['showpopup'];
$user_id = $_SESSION['user_id'];
$tweet = $getFromT->getPopupTweet($tweetID);
$user = $getFromU->userData($user_id);
$likes = $getFromT->likes($user_id, $tweetID);
$retweet = $getFromT->checkRetweet($tweetID, $user_id);
$comments = $getFromT->comments($tweetID);
?>
<div class="tweet-show-popup-wrap">
<input type="checkbox" id="tweet-show-popup-wrap">
<div class="wrap4">
<label for="tweet-show-popup-wrap">
<div class="tweet-show-popup-box-cut">
<i class="fa fa-times" aria-hidden="true"></i>
</div>
</label>
<div class="tweet-show-popup-box">
<div class="tweet-show-popup-inner">
<div class="tweet-show-popup-head">
<div class="tweet-show-popup-head-left">
<div class="tweet-show-popup-img">
<img src="<?php echo BASE_URL.$tweet->profileImage;?>"/>
</div>
<div class="tweet-show-popup-name">
<div class="t-s-p-n">
<a href="<?php echo BASE_URL.$tweet->username;?>">
<?php echo $tweet->screenName;?>
</a>
</div>
<div class="t-s-p-n-b">
<a href="<?php echo BASE_URL.$tweet->username;?>">
#<?php echo $tweet->username;?>
</a>
</div>
</div>
</div>
<div class="tweet-show-popup-head-right">
<button class="f-btn"><i class="fa fa-user-plus"></i> Follow </button>
</div>
</div>
<div class="tweet-show-popup-tweet-wrap">
<div class="tweet-show-popup-tweet">
<?php echo $getFromT->getTweetLinks($tweet->status);?>
</div>
<div class="tweet-show-popup-tweet-ifram">
<?php if(!empty($tweet->tweetImage)){?>
<img src="<?php echo BASE_URL.$tweet->tweetImage;?>"/>
<?php }?>
</div>
</div>
<div class="tweet-show-popup-footer-wrap">
<div class="tweet-show-popup-retweet-like">
<div class="tweet-show-popup-retweet-left">
<div class="tweet-retweet-count-wrap">
<div class="tweet-retweet-count-head">
RETWEET
</div>
<div class="tweet-retweet-count-body">
<?php echo $tweet->retweetCount;?>
</div>
</div>
<div class="tweet-like-count-wrap">
<div class="tweet-like-count-head">
LIKES
</div>
<div class="tweet-like-count-body">
<?php echo $tweet->likesCount;?>
</div>
</div>
</div>
<div class="tweet-show-popup-retweet-right">
</div>
</div>
<div class="tweet-show-popup-time">
<span><?php echo $tweet->postedOn;?></span>
</div>
<div class="tweet-show-popup-footer-menu">
<ul>
<?php if($getFromU->loggedIn() === true){
echo '<li><i class="fa fa-share" aria-hidden="true"></i></a></button></li>
<li>'.(($tweet->tweetID === $retweet['retweetID']) ? '<button class="retweeted" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><a href="#"><i class="fa fa-retweet" aria-hidden="true"></i><span class="retweetsCount">'.$tweet->retweetCount.'</span></button>' : '<button class="retweet" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><a href="#"><i class="fa fa-retweet" aria-hidden="true"></i><span class="retweetsCount">'.(($tweet->retweetCount > 0) ? $tweet->retweetCount : '').'</span></button>').'</li>
<li>'.(($likes['likeOn'] === $tweet->tweetID) ? '<button class="unlike-btn" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><i class="fa fa-heart-o" aria-hidden="true"></i><span class="likesCounter">'.$tweet->likesCount.'</span></button>' : '<button class="like-btn" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><i class="fa fa-heart" aria-hidden="true"></i><span class="likesCounter">'.(($tweet->likesCount > 0) ? $tweet->likesCount : '').'</span></button>').'</li>
<li>
<i class="fa fa-ellipsis-h" aria-hidden="true"></i>
<ul>
<li><label class="deleteTweet">Delete Tweet</label></li>
</ul>
</li>';
}else{
?>
<li><button type="buttton"><i class="fa fa-share" aria-hidden="true"></i></button></li>
<li><button type="button"><i class="fa fa-retweet" aria-hidden="true"></i><span class="retweetsCount">RETWEET-COUNT</span></button></li>
<li><button type="button"><i class="fa fa-heart" aria-hidden="true"></i><span class="likesCount">LIKES-COUNT</span></button></button></li>
<?php }?>
</ul>
</div>
</div>
</div><!--tweet-show-popup-inner end-->
<?php if($getFromU->loggedIn() === true){?>
<div class="tweet-show-popup-footer-input-wrap">
<div class="tweet-show-popup-footer-input-inner">
<div class="tweet-show-popup-footer-input-left">
<img src="<?php echo BASE_URL.$user->profileImage?>"/>
</div>
<div class="tweet-show-popup-footer-input-right">
<input id="commentField" type="text" name="comment" placeholder="Reply to #<?php echo $tweet->username;?>">
</div>
</div>
<div class="tweet-footer">
<div class="t-fo-left">
<ul>
<li>
<label for="t-show-file"><i class="fa fa-camera" aria-hidden="true"></i></label>
<input type="file" id="t-show-file">
</li>
<li class="error-li">
</li>
</ul>
</div>
<div class="t-fo-right">
<span id="count">140</span>
<input type="submit" id="postComment">
</div>
</div>
</div><!--tweet-show-popup-footer-input-wrap end-->
<?php }?>
<div class="tweet-show-popup-comment-wrap">
<div id="comments">
<?php
foreach ($comments as $comment) {
echo '<div class="tweet-show-popup-comment-box">
<div class="tweet-show-popup-comment-inner">
<div class="tweet-show-popup-comment-head">
<div class="tweet-show-popup-comment-head-left">
<div class="tweet-show-popup-comment-img">
<img src="'.BASE_URL.$comment->profileImage.'">
</div>
</div>
<div class="tweet-show-popup-comment-head-right">
<div class="tweet-show-popup-comment-name-box">
<div class="tweet-show-popup-comment-name-box-name">
'.$comment->screenName.'
</div>
<div class="tweet-show-popup-comment-name-box-tname">
#'.$comment->username.' - '.$comment->commentAt.'
</div>
</div>
<div class="tweet-show-popup-comment-right-tweet">
<p>#'.$tweet->username.' '.$comment->comment.'</p>
</div>
<div class="tweet-show-popup-footer-menu">
<ul>
<li><button><i class="fa fa-share" aria-hidden="true"></i></button></li>
<li><i class="fa fa-heart-o" aria-hidden="true"></i></li>
<li>
<i class="fa fa-ellipsis-h" aria-hidden="true"></i>
<ul>
<li><label class="deleteTweet">Delete Tweet</label></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
<!--TWEET SHOW POPUP COMMENT inner END-->
</div>
';
}
?>
</div>
</div>
<!--tweet-show-popup-box ends-->
</div>
</div>
<?php
}
?>
and the error on foreach that's means on this code
foreach ($comments as $comment) {
echo '<div class="tweet-show-popup-comment-box">
<div class="tweet-show-popup-comment-inner">
<div class="tweet-show-popup-comment-head">
<div class="tweet-show-popup-comment-head-left">
<div class="tweet-show-popup-comment-img">
<img src="'.BASE_URL.$comment->profileImage.'">
</div>
</div>
<div class="tweet-show-popup-comment-head-right">
<div class="tweet-show-popup-comment-name-box">
<div class="tweet-show-popup-comment-name-box-name">
'.$comment->screenName.'
</div>
<div class="tweet-show-popup-comment-name-box-tname">
#'.$comment->username.' - '.$comment->commentAt.'
</div>
</div>
<div class="tweet-show-popup-comment-right-tweet">
<p>#'.$tweet->username.' '.$comment->comment.'</p>
</div>
<div class="tweet-show-popup-footer-menu">
<ul>
<li><button><i class="fa fa-share" aria-hidden="true"></i></button></li>
<li><i class="fa fa-heart-o" aria-hidden="true"></i></li>
<li>
<i class="fa fa-ellipsis-h" aria-hidden="true"></i>
<ul>
<li><label class="deleteTweet">Delete Tweet</label></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
<!--TWEET SHOW POPUP COMMENT inner END-->
</div>
';
}
where is the error here ?
Arguments for foreach must be an array, you need to var_dump($comments) to see whether it's an array or not. In your case, returning result may be null so it returns warning for foreach. To ensure the foreach working, you may use this:
foreach ((array)$comments as $comment) {
}
I compared your code with mine and found a difference in this line: Do not worry, the error is there.
<li>
'.(($tweet->tweetID ===$retweet['retweetID']) ?
'<button class="retweeted" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><a href="#"><i class="fa fa-retweet" aria-hidden="true"></i><span class="retweetsCount">'.$tweet->retweetCount.'</span></button>'
:
'<button class="retweet" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><a href="#"><i class="fa fa-retweet" aria-hidden="true"></i><span class="retweetsCount">'.(($tweet->retweetCount > 0) ? $tweet->retweetCount : '') .'</span></button>' ).'<button class="retweet" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><a href="#"><i class="fa fa-retweet" aria-hidden="true"></i><span class="retweetsCount"></span></button>
</li>

Passing retrieved value from database into another page

how can i retrieve specific product details from this page to another page when i click the link?
This is my code for displaying all products in database:
<div class="features_items"><!--features_items-->
<h2 class="title text-center">Features Items</h2>
<?php
$product_array = $db_handle->runQuery("SELECT * FROM tblforface ORDER BY prodid ASC");
if (!empty($product_array)) {
foreach($product_array as $key=>$value){
?>
<div class="col-sm-4">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<img src="images/shop/product12.jpg" alt="" />
<h2><?php echo "₱".$product_array[$key]["prodprice"]; ?></h2>
<p><?php echo $product_array[$key]["prodname"]; ?></p>
<i class="fa fa-shopping-cart"></i>Add to cart
</div>
<div class="product-overlay">
<div class="overlay-content">
<h2><?php echo "₱".$product_array[$key]["prodprice"]; ?></h2>
<p><?php echo $product_array[$key]["prodname"]; ?></p>
<i class="fa fa-shopping-cart"></i>Add to cart
</div>
</div>
</div>
<div class="choose">
<ul class="nav nav-pills nav-justified">
<li><i class="fa fa-plus-square"></i>Add to wishlist</li>
<li><i class="fa fa-plus-square"></i>Add to compare</li>
</ul>
</div>
</div>
</div>
You can add the id into a query string, like http://blah.com/product.php?id=123
<a href="../homescreen/product/product.php?id=<?= $product_array[$key]["id"]; ?>" class="btn btn-default add-to-cart">
<i class="fa fa-shopping-cart"></i>Add to cart
</a>
And in your other page,
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
We do that instead of the dangerous $id = $_GET['id'];. Check the docs for filter_input here http://php.net/manual/en/function.filter-input.php

Yii2 Display Recently Added Members

I have a "Latest Staff Members" panel where it should display my recently added users. All I have is a static display of these users:
<div class="box box-danger <?= !User::isBizAdmin() ? 'hidden' : '' ?>">
<div class="box-header with-border">
<h3 class="box-title">Latest Staff Members</h3>
<div class="box-tools pull-right">
<span class="label label-danger">8 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="https://cdn2.iconfinder.com/data/icons/avatar-2/512/frank_man-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Alexander Pierce</a>
<span class="users-list-date">Today</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/Ben_man-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Norman</a>
<span class="users-list-date">Yesterday</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/iri_girl_face-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Jane</a>
<span class="users-list-date">12 Jan</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/Jay_man-128.png" alt="User Image"/>
<a class="users-list-name" href="#">John</a>
<span class="users-list-date">12 Jan</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/Fred_man-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Alexander</a>
<span class="users-list-date">13 Jan</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/michela_face_young-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Sarah</a>
<span class="users-list-date">14 Jan</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/carla_girl-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Nora</a>
<span class="users-list-date">15 Jan</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/hena_woman_face-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Nadia</a>
<span class="users-list-date">15 Jan</span>
</li>
</ul><!-- /.users-list -->
</div><!-- /.box-body -->
<div class="box-footer text-center">
View All Users
</div><!-- /.box-footer -->
</div>
Something like that. Now, in the user table in my database, I added a date_added column and I manually put dates in row.
Do I loop the data? Or use a widget? I don't know how else I should implement this.
EDIT
My controller:
public function actionIndex()
{
if(Yii::$app->user->isGuest){
return $this->render('../site/index');
}
else{
$latestStaffMembers = User::find()->orderBy(['date_added' => SORT_DESC])->limit(8);
return $this->render('dashboard', [
'latestStaffMembers' => $latestStaffMembers,
]);
}
}
In my view:
<?php foreach ($latestStaffMembers as $user) { ?>
<li>
<img src="<?php echo $user->avatar; ?>" alt="User Image"/>
<?= $user->username ?>
<span ><?= $user->date_added ?></span>
</li>
<?php } ?>
Then I get this error:
Trying to get property of non-object
I tried var-dumping $user and it says null.
I'm not sure if this is what you want. I hope it helps somehow.
In your controller action:
$latestStaffMembers = User::find()->orderBy(['date_added' => SORT_DESC])->limit(8)->all();
return $this->render('some-view-file', [
'latestStaffMembers' => $latestStaffMembers,
]);
In your view:
<?php foreach ($latestStaffMembers as $user) { ?>
<li>
<img src="<?= $user->imagePath ?>" alt="User Image"/>
<a class="users-list-name" href="#"><?= $user->name ?></a>
<span class="users-list-date"><?= Yii::$app->formatter->asDate($user->dateAdded, 'd m'); ?></span>
</li>
<?php } ?>
Btw: I saw !User::isBizAdmin() in your code. Is it yours? I would not just hide the list if it is important that only admins may see that. Just don't print it if user is not admin.

Categories