I wrote the following code to display some products on a page but all that I want is to display only 3 items in a row.
My code for displaying all products (i have to display more than 15 products):
<div class="products">
<div class="row">
#foreach($products as $item)
<div class="col-md-4 col-sm-6 col-xs-12 ">
<div class="blog-item item swin-transition">
<div class="block-img">
<img style="width: 269.844px;height: 254.984px " src="{{url('images/product/'.$item['image'])}}" alt="" class="img img-responsive">
<div class="group-btn">
<i class="icons fa fa-link"></i>
<i class="fa fa-shopping-basket"></i>
</div>
</div>
<div class="block-content">
<h6 class="title" style="font-size: 15px">
{{$item['name_'.$lang]}}
</h6>
<div class="product-info">
<ul class="list-inline">
<li class="author">
<span>{{Lang::get('frontend.price')}}:</span>
<span class="text">{{number_format($item['online_price'])}} {{Lang::get('frontend.unit')}}</span>
</li>
<li class="rating">
<a href="javascript:void(0)" tabindex="0">
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star-o"></i>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
#endforeach
</div>
</div>
php `array_chunk()` function will serve your purpose [http://php.net/manual/en/function.array-chunk.php][1]
<div class="products">
#foreach(array_chunk($products,3,true) as $chunk)
<div class="row">
#foreach($chunk as $item)
<div class="col-md-4 col-sm-6 col-xs-12 ">
<div class="blog-item item swin-transition">
<div class="block-img">
<img style="width: 269.844px;height: 254.984px " src="{{url('images/product/'.$item['image'])}}" alt="" class="img img-responsive">
<div class="group-btn">
<i class="icons fa fa-link"></i>
<i class="fa fa-shopping-basket"></i>
</div>
</div>
<div class="block-content">
<h6 class="title" style="font-size: 15px">{{$item['name_'.$lang]}}</h6>
<div class="product-info">
<ul class="list-inline">
<li class="author"><span>{{Lang::get('frontend.price')}}:</span><span class="text">{{number_format($item['online_price'])}} {{Lang::get('frontend.unit')}}</span></li>
<li class="rating"><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-o"></i></li>
</ul>
</div>
</div>
</div>
</div>
#endforeach
</div>
#endforeach;
</div>
[1]: http://php.net/manual/en/function.array-chunk.php
I have directory like this "localhost/site/folder1/file.php", I need to access file.php from "site" directory this way
href = "folder1/file.php"
unfortunately it takes me to
href = "folder1/folder1/file.php"
and when I access "index.php" file located in "site" directory from "folder1", this way
href = "../index.php"
it takes me to root directory in c: I mean this way
href = "localhost/index.php".
I have stacked with this problem for two days now, please any one to help me get out this.
Note: I am using bootstrap framework
More edit...
here is the full code.
<section>
<section class="hbox stretch">
<!-- .aside -->
<aside class="bg-black dk nav-xs aside hidden-print" id="nav">
<section class="vbox">
<section class="w-f-md scrollable">
<div class="slim-scroll" data-height="auto" data-disable-fade-out="true" data-distance="0" data-size="10px" data-railOpacity="0.2">
<!-- nav -->
<nav class="nav-primary hidden-xs">
<ul class="nav bg clearfix" data-ride="collapse">
<!--<li class="hidden-nav-xs padder m-t m-b-sm text-xs text-muted">
Discover
</li>-->
<li>
<a href= "../index.php">
<i class="icon-home icon text-success"></i>
<span class="font-bold">Home</span>
</a>
</li>
<li>
<a href="#" class="auto">
<span class="pull-right text-muted">
<i class="fa fa-angle-left text"></i>
<i class="fa fa-angle-down text-active"></i>
</span>
<i class="icon-music-tone-alt icon text-info"></i>
<span class="font-bold">Audios</span>
</a>
<ul class="nav dk text-sm">
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Speaches</span>
</a>
</li>
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Preaches</span>
</a>
</li>
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Interviews</span>
</a>
</li>
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Songs</span>
</a>
</li>
</ul>
</li>
<li>
<a href="#" class="auto">
<span class="pull-right text-muted">
<i class="fa fa-angle-left text"></i>
<i class="fa fa-angle-down text-active"></i>
</span>
<i class="icon-book-open icon text-primary-lter"></i>
<span class="font-bold">Writtings</span>
</a>
<ul class="nav dk text-sm">
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Books</span>
</a>
</li>
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Jounals</span>
</a>
</li>
</ul>
</li>
<li>
<a href="#">
<i class="icon-users icon text-primary-lter"></i>
<span class="font-bold">Artists</span>
</a>
</li>
<li>
<a href="#">
<i class="icon-film icon text-info-dker"></i>
<span class="font-bold">Albums</span>
</a>
</li>
<li class="m-b hidden-nav-xs"></li>
</ul>
<ul class="nav" data-ride="collapse">
<li class="hidden-nav-xs padder m-t m-b-sm text-xs text-muted">
User Account
</li>
<li>
<?php
if(!isset ($_SESSION['email'])){
echo "
<a href='../signin.php' class='auto'>
<i class='icon-login icon'>
</i>
<span>Signin</span>
</a>
</li>
<li >
<a href='../signup.php' class='auto'>
<i class='fa fa-smile-o'>
</i>
<span>Signup</span>
</a>
</li>
";
}else{
echo "
<a href='../signout.php' class='auto'>
<i class='icon-logout icon'>
</i>
<span>SignOut</span>
</a>
</li>";
if (!isset($_SESSION['admin_name'])) {
echo "
<li >
<a href='profile.php' class='auto'>
<i class='fa fa-smile-o'>
</i>
<span>My profile</span>
</a>
</li>
";
}else{
echo "
<li >
<a href='MembersManagement.php' class='auto'>
<i class='fa fa-edit'>
</i>
<span>Manage Member</span>
</a>
</li>
<li >
<a href='admin.php' class='auto'>
<i class='fa fa-edit'>
</i>
<span>My Dashboard</span>
</a>
</li>
";
}
}
?>
</ul>
</nav>
<!-- / nav ---->
</div>
</section>
And the problem is on this line
<nav class="nav-primary hidden-xs">
When I remove "nav-primary" everything is doing fine with the anchors () but it changes the appearance and arrangements in the section, what should I do, I am new to bootstrap frameworks.
If you are having problem with relative urls, you can try doing with absolute urls like :
href = "localhost/site/folder1/file.php".
and for the other one you can do same:
href = "localhost/site/index.php
Maybe this helps.
I have menu which is has sub menus.
<li>
<i class="fa fa-flag-checkered" aria-hidden="true"></i> <span>Lead</span> <i class="icon-submenu lnr lnr-chevron-left"></i>
<div id="lead" class="collapse ">
<ul class="nav">
<li><i class="fa fa-quote-right" aria-hidden="true"></i><span> Quotation </span><i class="icon-submenu lnr lnr-chevron-left"></i>
<div id="quotation" class="collapse ">
<ul class="nav">
<li><i class="fa fa-dot-circle-o" aria-hidden="true"></i> Create Quotation</li>
<li><i class="fa fa-dot-circle-o" aria-hidden="true"></i> Quotation Summary</li>
<li><i class="fa fa-dot-circle-o" aria-hidden="true"></i> Send Quotation</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
When I clicked it, I can not go directly to the page. I have to right-clicked on it to go to the desired page.
Here's an example of my controller
public function cquotation(){
$data = $this->salesModel->showCustomer();
$this->load->view('v_navbar');
$this->load->view('v_leftside');
$this->load->view('v_cquotation',array('data'=>$data));
}
Do you guys have any idea what's wrong with it?
I'm totally confused
Why are you using data-toggle="collapse" class="collapsed" on every hyperlink?. your code has data-toggle="collapse" class="collapsed" in every hyperlink.Bootstrap will prevent the default click event of a href .So remove every data-toggle="collapse" class="collapsed" part of a href in your code and it will work.
<li>
<i class="fa fa-flag-checkered" aria-hidden="true"></i> <span>Lead</span> <i class="icon-submenu lnr lnr-chevron-left"></i>
<div id="lead" class="collapse ">
<ul class="nav">
<li><i class="fa fa-quote-right" aria-hidden="true"></i><span> Quotation </span><i class="icon-submenu lnr lnr-chevron-left"></i>
<div id="quotation" class="collapse ">
<ul class="nav">
<li></i> Create Quotation</li>
<li></i> Quotation Summary</li>
<li></i> Send Quotation</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
I want to shorten a string when it's longer than a certain length for example 20.
But when I add the if statement to my echoed html it outputs the result outside of the echoed html. Any idea why this happens?
My code:
foreach($contentcr as $content)
{
$contentje .= '<li class="job_listing">
<a href="http://www.website.nl/_extern/website/content.php?alias='.$content['alias'].'">
<div class="location job_img">
<img src="images/samples/person1.jpg" alt="" class="company_logo">
</div>
<div class="location boldfont">
'.$content['title'].'
</div>
<div class="location">
'.$content['fulltext'].'';
if (strlen($content['fulltext']) >= 20){
echo 'blala';
}
$contentje .='</div>
<div class="rating location">
<div class="rating-stars">
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
</div>
</div>
<div class="location">
'.$content['metakey'].'
</div>
<div class="location">
<button type="submit" class="btn btn-primary buttonblock" onClick="location.href="http://www.website.nl/_extern/website/content.php?page="'.$content['alias'].'">Nu huren</button>
</div>
</a>
</li>'; // Here
}
This is a table like structure, but the output of the if statement is echoed outside the html markup.
You are echoing the string inside if statement rather than appending that to your $contentje variable. See if statement below:
foreach($contentcr as $content)
{
$contentje .= '<li class="job_listing">
<a href="http://www.website.nl/_extern/website/content.php?alias='.$content['alias'].'">
<div class="location job_img">
<img src="images/samples/person1.jpg" alt="" class="company_logo">
</div>
<div class="location boldfont">
'.$content['title'].'
</div>
<div class="location">
'.$content['fulltext'].'';
if (strlen($content['fulltext']) >= 20){
$contentje .= 'blala';
}
$contentje .='</div>
<div class="rating location">
<div class="rating-stars">
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
</div>
</div>
<div class="location"> '.$content['metakey'].'</div>
<div class="location">
<button type="submit" class="btn btn-primary buttonblock" onClick="location.href="http://www.website.nl/_extern/website/content.php?page="'.$content['alias'].'">Nu huren</button>
</div>
</a></li>'; // Here
}
The laravel paginator does work, but not good in my case.
So I have a forum with comments and the paginator must display when there are more than 10 comments on that page.
So I have a topic that has more than 10 comments and then it works fine on that page, but when I go to another page, he does take the pagination of the most comments. That is not what I want.
Here are some screens and code:
Here are there more than 10 comments, so it is good that it displays the paginator. The strange thing here is that it only shows 2 comments and not 10.
Here is another topic with just 8 comments, so the pagination shouldn't display anything:
But as you can see, it does show the paginator....
My code look like this:
Controller:
public function thread($title)
{
$thread = Thread::where('title', '=', str_replace('Thread-', '',str_replace('-', ' ', $title)))->first();
$usercolor = DB::table('threads')
->join('user', 'threads.uid', '=', 'user.id')
->join('role', 'user.role_id', '=', 'role.id')
->where('threads.uid', '=', $thread->uid)
->first();
$usertitle = DB::table('threads')
->join('user', 'threads.uid', '=', 'user.id')
->where('threads.uid', '=', $thread->uid)
->first();
$comments = Comment::orderBy('posted_at', 'asc')
->where('deleted_at', '=', '0000-00-00 00:00:00')
->with('user.role')
->paginate(10);
if (!$thread) {
return die('bestaat niet!');
}else{
return View::make('thread')->with('threads', $thread)
->with('comments', $comments)
->with('usercolor', $usercolor)
->with('usertitle', $usertitle);
}
}
View:
#include('globs.header')
<div class="col-sm-offset-1 col-sm-10">
<div class="clearfix"> </div>
#if(Request::get('page', 1) == 1)
<div class="panel panel-default" id="a9">
<div class="panel-heading">
<div class="panel-title">{{ $threads->title }}
</div>
</div>
<div class="panel-body thread-row">
<div class="row thread-row">
<div class="col-md-2 col-sm-3 text-center userblock">
<div class="clerafix"> </div>
<img class="img-thumbnail avatar" src="./public/img/avatar.jpg" alt="Avatar" height="55px;" width="55px">
<div class="push_bottom_5" style="color:{{ $usercolor->colour }};"><strong>{{ $threads->username }}</strong></div>
<div class="push_bottom_5"><small>{{ $usertitle->usertitle }}</small></div>
<div class="label label-default" style="background-color:{{ $usercolor->colour }};">{{ $usercolor->name }}</div>
<div class="push_bottom_5">
#if($usercolor->id == '1')
<i class="fa fa-star"></i>
#elseif($usercolor->id == '2')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($usercolor->id == '3')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($usercolor->id == '4')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($usercolor->id == '5')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($usercolor->id >= '6')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#endif
</div>
<div class="text-muted text-left"><small>Total Posts: 66</small></div>
<div class="text-muted text-left"><small>Joined 05-11-2014</small></div>
<div class="clerafix"> </div>
</div>
<div class="col-md-5 col-sm-6 col-xs-8">
<div class="clerafix"> </div>
<div class="text-muted"><span><i class="fa fa-calendar"></i> </span><small>
<span>Posted:</span> {{ date("d-m-Y", strtotime($threads->date_posted)) }}</small></div>
</div>
<div class="col-md-10 col-sm-9 col-xs-12">
<div class="clerafix"> </div>
<div class="content_body"><p>{{ Helper::Filter(BBCode::parse($threads->message)) }}</p>
</div>
<div class="clerafix"> </div>
</div>
</div>
</div>
<div class="panel-footer clearfix">
<div class="pull-right">
<!-- acties -->
<button class="btn btn-primary btn-sm"><i class="fa fa-edit"></i> Aanpassen</button>
<button class="btn btn-primary btn-sm"><i class="fa fa-quote-left"></i> Quote</button>
<button class="btn btn-danger btn-sm"><i class="fa fa-trash"></i> Verwijder</button>
<button class="btn btn-warning btn-sm"><i class="fa fa-exclamation"></i> Rapporteer</button>
</div>
</div>
</div>
<!-- end of the topic -->
</div>
#endif
<!-- begin of comments -->
#foreach($comments as $comment)
#if($comment->tid == $threads->tid)
<div class="col-sm-offset-1 col-sm-10">
<div class="clearfix"> </div>
<div class="panel panel-default" id="a9">
<div class="panel-body thread-row">
<div class="row thread-row">
<div class="col-md-2 col-sm-3 text-center userblock">
<div class="clerafix"> </div>
<img class="img-thumbnail avatar" src="./public/img/avatar.jpg" alt="Avatar" height="55px;" width="55px">
<div class="push_bottom_5" style="color:{{ $comment->user->role->colour }};"><strong>{{ $comment->username }}</strong></div>
<div class="push_bottom_5"><small>{{ $comment->user->usertitle }}</small></div>
<div class="label label-default" style="background-color:{{ $comment->user->role->colour }};">{{ $comment->user->role->name }}</div>
<div class="push_bottom_5">
#if($comment->user->role->id == '1')
<i class="fa fa-star"></i>
#elseif($comment->user->role->id == '2')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($comment->user->role->id == '3')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($comment->user->role->id == '4')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($comment->user->role->id == '5')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#elseif($comment->user->role->id >= '6')
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
#endif
</div>
<div class="text-muted text-left"><small>Total Posts: 66</small></div>
<div class="text-muted text-left"><small>Joined 05-11-2014</small></div>
<div class="clerafix"> </div>
</div>
<div class="col-md-5 col-sm-6 col-xs-8">
<div class="clerafix"> </div>
<div class="text-muted"><span class="hidden-md "><i class="fa fa-calendar"></i>
</span><small><span>Posted:</span> {{ date("d-m-Y", strtotime($comment->posted_at)) }}</small></div>
</div>
<div class="col-md-10 col-sm-9 col-xs-12">
<div class="clerafix"> </div>
<div class="content_body"><p>{{ Helper::Filter(BBCode::parse($comment->comment)) }}</p>
</div>
<div class="clerafix"> </div>
</div>
</div>
</div>
<div class="panel-footer clearfix">
<div class="pull-right">
<!-- acties -->
<button class="btn btn-primary btn-sm"><i class="fa fa-edit"></i> Aanpassen</button>
<button class="btn btn-primary btn-sm"><i class="fa fa-quote-left"></i> Quote</button>
<button class="btn btn-danger btn-sm"><i class="fa fa-trash"></i> Verwijder</button>
<button class="btn btn-warning btn-sm"><i class="fa fa-exclamation"></i> Rapporteer</button>
</div>
</div>
</div>
</div>
#endif
#endforeach
<!-- end of comments -->
#if(Auth::check())
<div class="col-sm-offset-1 col-sm-10">
<div class="clearfix"> </div>
<div class="panel panel-default" id="a9">
<div class="panel-heading"><h4>Snelle reactie plaatsen</h4></div>
<div class="panel-body">
{{ Form::open(array('url' => 'SubmitComment')) }}
<input type="hidden" value="{{ $threads->tid }}" name="tid">
{{ Honeypot::generate('spamprt', 'time') }}
<textarea name="comment" class="form-control" col="250" rows="5" placeholder="Typ uw bericht..."></textarea>
<div class="clearfix"> </div>
<button class="btn btn-success pull-left" type="submit" name="action">
Reageer
</button>
{{ Form::close() }}
</div>
</div>
</div>
#endif
<div class="col-md-4 col-md-offset-5">{{ $comments->links() }}</div>
</div>
</div>
#include('globs.footer')
I hope you guys will understand my problem and are be able to find a perfect solution with me.
It looks like you always retrieve all comments. I can also see this in your template, where you wrap your code in #if($comment->tid == $threads->tid) within your foreach.
This means that later in your template, where you retrieve the pagination links, it will retrieve the links for all comments, but not all comments are shown in the page, since you filter them manually in the loop.
Query the comments like
$comments = Comment::orderBy('posted_at', 'asc')
->where('deleted_at', '=', '0000-00-00 00:00:00')
->where('tid', $threads->tid) // it's about this line!
->with('user.role')
->paginate(10);
Note:
Above should provide a solution for your problem, but as an extra, you could also look into relationships. As an addition, this answer on SO "Laravel 4.1: How to paginate eloquent eager relationship?" (Since you tagged your post with Laravel-4) has some nice arguments on how to approach this efficiently.