display 4 book details per row in image slider - php

I have coded this image slider that moves the image and it's details using the cursor.
I want to fetch data from database and display 4 books images with their details in each row I have tried this code but all the data have displayed in one row only.
Also if this does not take much of your time I want to make only 7 rows per page (28 books) and add numbers at the bottom of the page to move to the next 7 rows.
this is my try :
<html>
<body>
<div class="popular_causes_area section_padding">
<div class="container"> <div class="row">
<div class="col-lg-12">
<div class="causes_active owl-carousel">
<?php
try{
require('connection.php');
$sql1="select * from books ";
$rs=$db->query($sql1);
$db =null;
} catch(PDOException $ex) {
die ("Error Message ".$ex->getMessage()); }
$i=0;
while ($books = $rs->fetch()){
$i++;
$bpic = $books[2];
$btitle= $books[3];
$bq= $books[4];
$bstatus = $books[5];
$bdesc = $books[6];
$bnumber = $books[7];
$bcity = $books[8];
if ($i % 3 == 1) {
echo "<li>"; ?>
<div class="single_cause">
<div class="thumb">
<?php
if ($bpic == "" ) {
echo "<img src='img/default-image.png'
height=450px'>";
} else {
echo "<img src='img/$bpic' placeholder='nooooo'
height=450px alt=''>";
}?>
</div>
<div class="causes_content">
<div class="balance d-flex justify-content-between align-items-center">
<span>Tell:<?php echo $bnumber; ?> </span>
<span><?php echo $bcity; ?> </span>
</div>
<h4><?php echo $btitle; ?> </h4>
<p><?php echo $bdesc; echo "<br>
condation:".$bstatus; ?> </p>
</div>
</div>
</li>
<?php
} ////end of first if
if ($i % 3 == 0) {
echo "<li>"; ?>
<div class="single_cause">
<div class="thumb">
<?php
if ($bpic == "" ) {
echo "<img src='img/default-image.png' height=450px'>";
} else {
echo "<img src='img/$bpic' placeholder='nooooo' height=450px alt=''>"; ?>
</div>
<div class="causes_content">
<div class="balance d-flex justify-content-between align-items-center">
<span>Tell:<?php echo $bnumber; ?> </span>
<span><?php echo $bcity; ?> </span>
</div>
<h4><?php echo $btitle; ?> </h4>
<p><?php echo $bdesc; echo "<br>
condation:".$bstatus; ?> </p>
</div>
</div>
</li>
<?php
} //end of second if
} // end of while ?>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
This image shows what I got (all the data in one row instead of 4 books per row !):
image slider code :
<div class="popular_causes_area section_padding">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="causes_active owl-carousel">
<div class="single_cause">
<div class="thumb">
<?php
if ($bpic == "" ) {
echo "<img src='img/default-image.png' height=450px'>";
} else {
echo "<img src='img/$bpic' placeholder='nooooo' height=450px alt=''>";
}
?>
</div>
<div class="causes_content">
<div class="balance d-flex justify-content-between align-items-center">
<span>Tell:<?php echo $bnumber; ?> </span>
<span><?php echo $bcity; ?> </span>
</div>
<h4><?php echo $btitle; ?> </h4>
<p><?php echo $bdesc; echo "<br> condation:".$bstatus; ?> </p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Related

How to use card-deck with dynamically generated data?

I want to display data use card-deck. So every three data from database, it will make a new line. So, one line just have 3 datas, how to fix it?
Here my code, it display one line with all data from database and how to fix it?
<?php for($i=0; $i<count($data); $i++){
if($i % 3 == 0){?>
<div class="card-deck ml-2 mr-2 mb-3">
<?php $no=1; foreach ($data as $d ){?>
<div class="card border-dark">
<img class="card-img-top" src="<?php echo base_url('assets/koceng.jpeg')?>" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text"><?php echo $no++ ?>
<?php echo $d->nim ?>
<?php echo $d->nama ?>
<?php echo $d->kelas ?>
<?php echo $d->nama_jurusan ?>
<?php echo $d->fakultas ?></p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
<?php }?>
</div>
<?php }}?>
Thankyou.
Take a look at this tutorial.
<?php $i = 0;foreach ($data as $d ){?> <!-- i is for count number of cards -->
<?php if($i%3 == 0){ ?> <!-- printing card-deck per 3 cards -->
<div class="card-deck ml-2 mr-2 mb-3">
<?php } ?>
<div class="card border-dark">
<img class="card-img-top" src="<?php echo base_url('assets/koceng.jpeg')?>" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text"><?php echo $no++ ?> <!-- i don't know why $no is used for -->
<?php echo $d->nim ?>
<?php echo $d->nama ?>
<?php echo $d->kelas ?>
<?php echo $d->nama_jurusan ?>
<?php echo $d->fakultas; $i++;?></p> <!-- increment i by one per card -->
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
<?php if($i%3 == 0){ ?>
</div>
<?php } } ?>

How to sort replies by date - latest reply show first

first i want to apologize for my bad english, but i want to ask:
I have a ticketing system and i want to sort my replies by latest reply. Now the sorting is from oldest and now i want to sort by newest
I am using CodeIgniter as framework, and Perfex CRM as script
That's a part of my code, i don't know what can i do for sorting>
<div class="panel-footer">
<?php echo _l('ticket_posted',_dt($ticket->date)); ?>
</div>
</div>
<?php foreach($ticket_replies as $reply){ ?>
<div class="panel_s">
<div class="panel-body <?php if($reply['admin'] == NULL){echo 'client-reply';} ?>">
<div class="row">
<div class="col-md-3 border-right ticket-submitter-info">
<p>
<?php if($reply['admin'] == NULL || $reply['admin'] == 0){ ?>
<?php if($reply['userid'] != 0){ ?>
<?php echo $reply['submitter']; ?>
<?php } else { ?>
<?php echo $reply['submitter']; ?>
<br />
<?php echo $reply['reply_email']; ?>
<?php } ?>
<?php } else { ?>
<?php echo $reply['submitter']; ?>
<?php } ?>
</p>
<p class="text-muted">
<?php if($reply['admin'] !== NULL || $reply['admin'] != 0){
echo _l('ticket_staff_string');
} else {
if($reply['userid'] != 0){
echo _l('ticket_client_string');
}
}
?>
</p>
<hr />
<?php echo _l('delete_ticket_reply'); ?>
<div class="clearfix"></div>
<?php if(has_permission('tasks','','create')){ ?>
<a href="#" class="pull-left btn btn-default mtop5 btn-xs" onclick="convert_ticket_to_task(<?php echo $reply['id']; ?>,'reply'); return false;"><?php echo _l('convert_to_task'); ?>
</a>
<div class="clearfix"></div>
<?php } ?>
</div>
<div class="col-md-9">
<div class="row">
<div class="col-md-12 text-right">
<?php if(!empty($reply['message'])) { ?>
<i class="fa fa-print"></i>
<?php } ?>
<i class="fa fa-pencil-square-o"></i>
</div>
</div>
<div class="clearfix"></div>
<div data-reply-id="<?php echo $reply['id']; ?>" class="tc-content">
<?php echo check_for_links($reply['message']); ?>
</div>
<?php if(count($reply['attachments']) > 0){
echo '<hr />';
foreach($reply['attachments'] as $attachment){
$path = get_upload_path_by_type('ticket').$ticket->ticketid.'/'.$attachment['file_name'];
$is_image = is_image($path);
if($is_image){
echo '<div class="preview_image">';
}
?>
<a href="<?php echo site_url('download/file/ticket/'. $attachment['id']); ?>" class="display-block mbot5"<?php if($is_image){ ?> data-lightbox="attachment-reply-<?php echo $reply['id']; ?>" <?php } ?>>
<i class="<?php echo get_mime_class($attachment['filetype']); ?>"></i> <?php echo $attachment['file_name']; ?>
<?php if($is_image){ ?>
<img class="mtop5" src="<?php echo site_url('download/preview_image?path='.protected_file_url_by_path($path).'&type='.$attachment['filetype']); ?>">
<?php } ?>
</a>
<?php if($is_image){
echo '</div>';
}
if(is_admin() || (!is_admin() && get_option('allow_non_admin_staff_to_delete_ticket_attachments') == '1')){
echo ''._l('delete').'';
}
echo '<hr />';
}
} ?>
</div>
</div>
</div>
<div class="panel-footer">
<span><?php echo _l('ticket_posted',_dt($reply['date'])); ?></span>
</div>
</div>
<?php } ?>
</div>
</div>
<div class="btn-bottom-pusher"></div>
<?php if(count($ticket_replies) > 1){ ?>
↑
↓
<?php } ?>
</div>
</div>
In the 5th line of this snippet
<?php foreach($ticket_replies as $reply)
$ticket_replies is the result of some query (which is not pasted here). Also from this line
<span><?php echo _l('ticket_posted',_dt($reply['date'])); ?></span>
it can be seen that there is a 'date' column. As already mentioned in the comment above add 'ascending' or 'descending' order by clause to the query.

add additional echo in if statement

I have this following snippet:
<?php
if($people->num_rows >= 1) {
while($person = $people->fetch_object()) {
echo '
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="card card-user">
<div class="content">
<div class="author">
<a href="'.$system->getDomain()?>/user/<?=$person->id.'">
<img class="avatar" src="'.$system->getProfilePicture($person).'">
<h4 class="title">'.$system->getFirstName($person->full_name).', '.$person->age.'</h4>
</a>
</div>
<p class="text-center text-muted">
';
echo $person->city.$system->ifComma($person->city); echo ' '.$person->country.'
</p>
</div>
</div>
</div>
';
}
} else {
?>
however next to the actual age (after the closing H4 tag) I'd like to add a further function which shows the current online status of the user.
The code for this would be as follows:
<?php if($system->isOnline($profile->last_active)) { echo '<i class="online-status online"></i>'; } else { echo '<i class="online-status offline"></i>'; } ?>
What is the best way to combine this snippet (online status) with the statement above?
Some expert help would be greatly appreciated
Separate your HTML and PHP code and do it like the below. Your requirement is done using a single line ternary operator.
<?php
if($people->num_rows >= 1) {
while($person = $people->fetch_object()) { ?>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="card card-user">
<div class="content">
<div class="author">
<a href="<?php echo $system->getDomain().'/user/'.$person->id;?>">
<img class="avatar" src="<?php echo $system->getProfilePicture($person);?>">
<h4 class="title"><?php echo $system->getFirstName($person->full_name).', '.$person->age;?></h4>
<?php echo ($system->isOnline($profile->last_active)) ? '<i class="online-status online"></i>' : '<i class="online-status offline"></i>'; ?>
</a>
</div>
<p class="text-center text-muted">
<?php echo $person->city.$system->ifComma($person->city); echo ' '.$person->country;?>
</p>
</div>
</div>
</div>
<?php
}
}
?>

If/else statement inside the same div tag (formatting)

I'm trying to get the formatting of php and html in the same document right. I can't seem to get the conversion right.
....
This is the original HTML:
<div class="content-holder clearfix">
<div class="container">
<div class="row">
<div class="span12">
<div class="row">
<div id="title-header" class="span12">
<div class="page-header">
<?php get_template_part("static/static-title"); ?>
</div>
</div>
<div class="row">
<?php if ($masonrycategory=='false') { ?>
<div class="span8 <?php if (of_get_option('blog_sidebar_pos')==''){echo 'right';}else{echo of_get_option('blog_sidebar_pos'); } ?>" id="content">
<?php get_template_part("loop/loop-blog-main"); ?>
</div>
<div class="span4 sidebar" id="sidebar">
<?php dynamic_sidebar("hs_main_sidebar"); ?>
</div>
<?php }else{ ?>
<div class="span12 id="content">
<?php get_template_part("loop/loop-blog-masonry"); ?>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
And I need to convert it to PHP.
...
} else {
echo "<div class='content-holder clearfix'>";
echo "<div class='container'>";
echo "<div class='row'>";
echo "<div class='span12'>";
echo "<div class='row'>";
echo "<div id='title-header' class='span12'>";
echo "<div class='page-header'>";
get_template_part("static/static-title");
echo "</div>";
echo "</div>";
echo "<div class='row'>"
if ($masonrycategory=='false') {
echo "<div class='span8' . 'if (of_get_option('blog_sidebar_pos')==''){echo 'right';}else{echo of_get_option('blog_sidebar_pos'); } ?>" id="content">
<?php get_template_part("loop/loop-blog-main"); ?>
</div>
<div class="span4 sidebar" id="sidebar">
<?php dynamic_sidebar("hs_main_sidebar"); ?>
</div>
<?php }else{ ?>
<div class="span12 id="content">
<?php get_template_part("loop/loop-blog-masonry"); ?>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
} ?>
Syntax error:
echo "<div class='span8' . 'if (of_get_option('blog_sidebar_pos')==''){echo 'right';}else{echo of_get_option('blog_sidebar_pos'); } ?>" id="content">
Until you are more confident, you might find it easier to be more vebose in your style of coding:
echo '<div class="span8';
if (of_get_option('blog_sidebar_pos') == '') {
echo ' right';
} else {
echo of_get_option('blog_sidebar_pos');
}
echo '" id="content">';
You can use the if else shorthand like this:
div class="span8 <?php $v= (of_get_option('blog_sidebar_pos')=='')? 'right':of_get_option('blog_sidebar_pos') ;echo $v;?>" id="content">
Considering of_get_option fn does't have any error.

How to divide categories in rows of three columns

I have a foreach loop which retrieves the subcategories of the current category.
<?php $_categories = $this->getCurrentChildCategories(); ?>
<?php foreach ($_categories as $_category): ?>
<div class="item">
<?php echo $this->htmlEscape($_category->getName()) ?>
</div>
<?php endforeach; ?>
I want to divide the results in rows of three columns. The desired format is then:
<div class="row">
<div class="item">
content
</div>
<div class="item">
content
</div>
<div class="item">
content
</div>
</div>
<div class="row">
<div class="item">
content
</div>
<div class="item">
content
</div>
<div class="item">
content
</div>
</div>
...
---------------EDIT----------------
My code is now as follows. How and where do i close the row div?
<?php $_categories = $this->getCurrentChildCategories(); ?>
<?php foreach ($_categories as $_category): ?>
<?php if ($i % 3 == 0) { ?>
<div class="row">
<?php } ?>
<div class="item">
<h2><?php echo $this->htmlEscape($_category->getName()) ?> »</h2>
</div>
<?php $i++; endforeach; ?>
---------------EDIT 2----------------
Getting closer. This is the result:
<div class="category-list">
<div class="row"></div>
<div class="row">
<div class="item">
content
</div>
<div class="item">
content
</div>
<div class="item">
content
</div>
</div>
<div class="row">
<div class="item">
content
</div>
<div class="item">
content
</div>
<div class="item">
content
</div>
</div>
<div class="row">
<div class="item">
content
</div>
<div class="item">
content
</div>
<div class="item">
content
</div>
</div>
</div>
How do I get rid of the empty row?
The code is now as follows:
<div class="category-list">
<?php
$i=0;
echo '<div class="row">';
$_categories = $this->getCurrentChildCategories();
foreach($_categories as $_category):
{
if($i %3 ==0)
{ ?>
</div>
<div class="row">
<div class="item">
<h2><?php echo $this->htmlEscape($_category->getName()) ?> »</h2>
</div>
<? }
else
{ ?>
<div class="item">
<h2><?php echo $this->htmlEscape($_category->getName()) ?> »</h2>
</div>
<? }
$i++;
}
endforeach;
?>
</div>
---------------EDIT 3----------------
Solved by hiding the empty row via CSS.
You have to introduce az iterator (?) variable for example $i = 0
if ($i % 3 == 0) { //modulo
// use for whatever you want
}
In every cycle (maybe at the end of it, it depends on your real solution) you have to increment $i (++$i);
Hope this helps
<?php
$i=0;
echo"<div class="row" >
foreach($category as $cat)
{
if($i %3 ==0)
{
echo"</div><div class='row'> <div class='item'> Content </div>";
}
else
{
echo"<div class='item'> Content </div>";
}
$i++;
}
echo"</div>";
?>

Categories