I have created a home page in codeigniter and have created a home controller in it. Index method has been created in the home controller, in which all articles have been shown.
Now another function is added in the home controller in which to show all articles of single category, I also made model but in this show all articles in all categories.
If I am calling only method then query is working but showing in home html page then all data showing all category.please help me
<?php
class Home extends CI_Controller{
function index(){
$this->load->model('Article_model');
$param['offset']=4;
$param['limit']=0;
$articles=$this->Article_model->getArticlesFront($param);
$data['articles']=$articles;
$this->load->view('front/home',$data);
}
function computerCategory(){
$this->load->model('Article_model');
$param['offset']=4;
$param['limit']=0;
$articles=$this->Article_model->getComputerArticlesFront($param);
$data['articles']=$articles;
$this->load->view('front/computer_category',$data);
}
}
?>
/*front computer category methods*/
function getComputerArticlesFront($param= array()){
$query = $this->db->get('articles');
if(isset($param['offset']) && isset($param['limit'])){
$this->db->limit($param['offset'],$param['limit']);
}
if(isset($param['q'])){
$this->db->or_like('title',trim($param['q']));
$this->db->or_like('author',trim($param['q']));
}
if(isset($param['category_id'])){
$this->db->where('category',$param['category_id']);
}
$this->db->select('articles.*,categories.name as category_name');
$this->db->where('articles.category',43);
$this->db->order_by('articles.created_at','DESC');
$this->db->join('categories','categories.id=articles.category','left');
$query = $this->db->get('articles');
//echo $this->db->last_query();
$articles = $query->result_array();
//echo $this->db->last_query();
return $articles;
}
<!--computer news start-->
<?php if(!empty($articles)){?>
<div class="pb-4 pt-4">
<div class="container">
<div class="row gx-4">
<div class="p-3 border bg-success text-white">
<h3>कंप्यूटर</h3>
</div>
</div>
<div class="row pb-3 pt-4">
<?php foreach ($articles as $article) {?>
<div class="col-md-3">
<div class="card">
<?php if(file_exists('./public/uploads/articles/thumb_admin/'.$article['image'])){?>
<img src="<?php echo base_url('public/uploads/articles/thumb_admin/'.$article['image'])?>" class="card-img-top" alt="">
<?php }?>
<div class="card-body">
<p class="card-text"><?php echo $article['title'];?></p>
Go somewhere
</div>
</div>
</div><!--card 1-->
<?php }?>
</div>
</div>
</div><!--latest blogs-->
<?php }?>
<!--computer news end-->
this page is being open but when i put this page then show all category
just like
<?php $this->load->view('front/header'); ?>
<div class="container pt-4 pb-4">
<h3 class="pb-3">About Company</h3>
<p class="text-muted"> Nike clearly knows its audience and makes their mission obvious to them as soon as they land on the About Us page. There's no question that the visitor is in the right place and understands exactly what Nike has set out to do. </p>
<p class="text-muted"> Nike clearly knows its audience and makes their mission obvious to them as soon as they land on the About Us page. There's no question that the visitor is in the right place and understands exactly what Nike has set out to do. </p>
</div>
<!--computer category list-->
<?php if(!empty($articles)){?>
<?php $this->load->view('front/computer_category');?>
<?php }?>
<!--yoga news start-->
<?php if(!empty($articles)){?>
<div class="pb-4 pt-4">
<div class="container">
<div class="row gx-4">
<div class="p-3 border bg-success text-white">
<h3>योग</h3>
</div>
</div>
<div class="row pb-3 pt-4">
<?php foreach ($articles as $article) {?>
<div class="col-md-3">
<div class="card">
<?php if(file_exists('./public/uploads/articles/thumb_admin/'.$article['image'])){?>
<img src="<?php echo base_url('public/uploads/articles/thumb_admin/'.$article['image'])?>" class="card-img-top" alt="">
<?php }?>
<div class="card-body">
<p class="card-text"><?php echo $article['title'];?></p>
Go somewhere
</div>
</div>
</div><!--card 1-->
<?php }?>
</div>
</div>
</div><!--latest blogs-->
<?php }?>
<!--yoga news end-->
<!--lifestyle news start-->
<?php $this->load->view('front/lifestyle');?>
<!--lifestyle news end-->
<!--technology news start-->
<?php if(!empty($articles)){?>
<div class="pb-4 pt-4">
<div class="container">
<div class="row gx-4">
<div class="p-3 border bg-success text-white">
<h3>लाइफस्टाइल</h3>
</div>
</div>
<div class="row pb-3 pt-4">
<?php foreach ($articles as $article) {?>
<div class="col-md-3">
<div class="card">
<?php if(file_exists('./public/uploads/articles/thumb_admin/'.$article['image'])){?>
<img src="<?php echo base_url('public/uploads/articles/thumb_admin/'.$article['image'])?>" class="card-img-top" alt="">
<?php }?>
<div class="card-body">
<p class="card-text"><?php echo $article['title'];?></p>
Go somewhere
</div>
</div>
</div><!--card 1-->
<?php }?>
</div>
</div>
</div><!--latest blogs-->
<?php }?>
<!--technology news end-->
<div class="bg-light pb-4">
<div class="container">
<h3 class="pb-3 pt-4">OUR SERVICES</h3>
<div class="row">
<div class="col-md-3">
<div class="card">
<img src="<?php echo base_url('public/images/box1.jpg');?>" class="card-img-top" alt="">
<div class="card-body">
<h5 class="card-title">Website Development</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div><!--card 1-->
<div class="col-md-3">
<div class="card">
<img src="<?php echo base_url('public/images/box2.jpg');?>" class="card-img-top" alt="">
<div class="card-body">
<h5 class="card-title">Website Development</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div><!--card 1-->
<div class="col-md-3">
<div class="card">
<img src="<?php echo base_url('public/images/box3.jpg');?>" class="card-img-top" alt="">
<div class="card-body">
<h5 class="card-title">Website Development</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div><!--card 1-->
<div class="col-md-3">
<div class="card">
<img src="<?php echo base_url('public/images/box4.jpg');?>" class="card-img-top" alt="">
<div class="card-body">
<h5 class="card-title">Website Development</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div><!--card 1-->
</div>
</div>
</div><!--our services-->
<?php if(!empty($articles)){?>
<div class="pb-4 pt-4">
<div class="container">
<h3 class="pb-3 pt-4">LATEST BLOGS</h3>
<div class="row">
<?php foreach ($articles as $article) {?>
<div class="col-md-3">
<div class="card">
<?php if(file_exists('./public/uploads/articles/thumb_admin/'.$article['image'])){?>
<img src="<?php echo base_url('public/uploads/articles/thumb_admin/'.$article['image'])?>" class="card-img-top" alt="">
<?php }?>
<div class="card-body">
<p class="card-text"><?php echo $article['title'];?></p>
Go somewhere
</div>
</div>
</div><!--card 1-->
<?php }?>
<!--<div class="col-md-3">
<div class="card">
<img src="<?php echo base_url('public/images/box2.jpg');?>" class="card-img-top" alt="">
<div class="card-body">
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>card 1-->
<!--<div class="col-md-3">
<div class="card">
<img src="<?php echo base_url('public/images/box3.jpg');?>" class="card-img-top" alt="">
<div class="card-body">
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>card 1-->
<!--<div class="col-md-3">
<div class="card">
<img src="<?php echo base_url('public/images/box4.jpg');?>" class="card-img-top" alt="">
<div class="card-body">
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>card 1-->
</div>
</div>
</div><!--latest blogs-->
<?php }?>
load->view('front/footer'); ?>
then page show
in this page all category article show
i requesting to all please help me
Related
I have a display_all_groups.php page that display a bootstrap card of all groups created by user. When users click on "View Group" hyperlink it will direct them to view_group.php
Here are my code
session_start();
require_once $_SERVER["DOCUMENT_ROOT"].'/mindspace/Business Services Layer/ManageGroupsController/GroupsController.php';
$std_id = $_SESSION['std_id'];
$group = new ManageGroupsController();
$data = $group->viewGroups($std_id);
?>
<div class="main-panel">
<div class="content-wrapper">
<div class="row">
<div class="col-12 grid-margin stretch-card">
<form method="post">
<?php
foreach($data as $row){
?>
<div class="card-body">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="../../template/images/banner.png" alt="Card image cap">
<div class="card-body">
<h5 class="card-title"><?=$row['group_name']?></h5>
<p class="card-text"></p>
<a class="btn btn-primary" href="view_group.php?group_id=<?=$row['group_id']?>">View Group</a>
</div>
</div>
</div>
</form>
<?php } ?>
</div>
</div>
</div>
</div>
When I try to click on the View Group button, it did not bring me to other page that I want it to. Please help, Im very new to PHP
It's hard to say exactly what the problem could be. First I would always check that $data is not empty. Then the keys are named correctly. I don't know the data object.
If everything is correct, then it should work. A small note: In the link there is still a simple quotation mark. You should delete that too.
<?= $row['group_id']?> >>>>**'**<<<< "
<?php session_start();
require_once $_SERVER["DOCUMENT_ROOT"] . '/mindspace/Business Services Layer/ManageGroupsController/GroupsController.php';
$std_id = $_SESSION['std_id'];
$group = new ManageGroupsController();
$data = $group->viewGroups($std_id);
?>
<div class="main-panel">
<div class="content-wrapper">
<div class="row">
<div class="col-12 grid-margin stretch-card">
<form method="post">
<?php
foreach ($data as $row) {
?>
<div class="card-body">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="../../template/images/banner.png" alt="Card image cap">
<div class="card-body">
<h5 class="card-title"><? echo $row['group_name']; ?></h5> <!-- Used echo -->
<p class="card-text"></p>
<a class="btn btn-primary" href="view_group.php?group_id=<? echo $row['group_id']; ?>">View Group</a> <!-- used echo, removed extra single quote -->
</div>
</div>
</div>
</form>
<?php } ?>
</div>
</div>
</div>
</div>
I had done a few changes in the code,
Used echo
Removed an additional single quote
Below is my code the posts are displaying fine with card but I have tried many times changing it to carousel but it didn't worked.
I wanted to use the same carousel from the link below.
Carousel reference: https://gosnippets.com/snippets/bootstrap-carousel-with-cards-in-3-columns
<?php
//var_dump($get_packages_list);
if($get_packages_list){
foreach($get_packages_list as $get_package){?>
<div class="row">
<div class="col-md-12">
<div class="packages_list_body">
<div class="packages_cards_inner_wrap" id="package-<?php echo $get_package->post_name;?>">
<h2 id="bundle_p_title" style="color:#a52a2a; margin-left: 12px;"><?php echo $get_package->post_title.' - <small>'.$default_plan_title.'</small>';?></h2>
<div class="packages_cards row">
<?php
$podcasts = get_field('podcasts', $get_package->ID);
$minimum_price = get_field('minimum_price', $get_package->ID);
$package_title = 'Pay at least $'.$minimum_price.' for these '.$podcast_count.' items';
foreach($podcasts as $podcast){
$podcast_details = get_post($podcast);
$image = get_the_post_thumbnail_url(get_the_ID(), array('250', '250'));
$image = $image?$image:wp_get_attachment_image_src(8059, 'thumbnail');
?>
<div class="col-md-3">
<div class="card <?php echo 'package-'.$get_package->ID.' podcast-'.$podcast_details->ID;?>" data-price="<?php echo $minimum_price;?>" data-packageid="<?php echo $get_package->ID;?>">
<img src="<?php echo $image[0];?>" alt="<?php echo $podcast_details->post_title; ?>" class="card-img-top">
<div class="card-body">
<h3><?php echo substr($podcast_details->post_title, 0, 20) . ' ...';?></h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
</div>
</div>
<?php }?>
</div>
</div>
</div>
</div>
</div>
<?php }
}?>
I have to make it all HTML to see that if it works. I hope you can rewrite it back to PHP later.
<div class="row">
<div class="col-md-12">
<div class="packages_list_body">
<div class="packages_cards_inner_wrap" id="package-xxx">
<h2 id="bundle_p_title" style="color:#a52a2a; margin-left: 12px;">Title here</h2>
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active group-of-cards">
<div class="packages_cards row">
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title1</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title2</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title3</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
</div>
<!--.packages_cards-->
</div>
<!--.group-of-cards-->
<div class="carousel-item group-of-cards">
<div class="packages_cards row">
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title4</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title5</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title6</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
</div>
<!--.packages_cards-->
</div>
<!--.group-of-cards-->
</div>
<!--.carousel-inner-->
</div>
<!--.carousel-->
</div>
<!--.packages_cards_inner_wrap-->
</div>
<!--.packages_list_body-->
</div>
</div>
<!--.row-->
See it in action ( https://jsfiddle.net/qt60whLf/ ).
Bootstrap 4 document ( https://getbootstrap.com/docs/4.0/components/carousel/ ).
I want the information tag to be at the right side of the web page. Rest of the things are in the middle of the page. While I am not able to move the information to the right side. Also, because of it the footer disappeared. While I remove the information code, the footer works. Please help me right-align the information widget and also have the footer too.
<div class="container">
<div class="card border-light mb-3 text-center">
<p class="card-header">Videos</p>
</div>
<div id="userSuccess" class="hide" role="alert">
<div id="successUserContent"></div>
</div>
<div class="row" id="userVid">
<?php
$allVid = Schema::getAll();
for ($i = 0; $i < count($allVid); $i++) {
echo <<<HTML
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100">
<div class="card-body">
<img class="card-img-top" src="http://placehold.it/700x400" alt="">
<h4 class="card-title">{$allVid[$i]->getTitle()} </h4>
</div>
</div>
</div>
HTML;
}
?>
</div>
<div class="row">
<div class="col-md-4 order-md-2 mb-4">
<div class="card my-4">
<h5 class="card-header">Information</h5>
<div class="card-body">
<div class="row">
<ul class="list-unstyled mb-0">
<li>
...
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
require_once './page/footer.php';
?>
For right align, you'll want to add the class of "justify-content-end" after your "row" class.
<div class="row justify-content-end"><!-- ADDED HERE-->
<div class="col-md-4 order-md-2 mb-4">
<div class="card my-4">
<h5 class="card-header">Information</h5>
<!-- REST OF YOUR CODE-->
For your footer, you'll need to wrap your URL in parenthesis.
<?php require_once('/yourdirectory/yourfooter.php'); ?>
I am generating html code using php. I have some information stored in an array called $persons and I'm trying to generate a bootstrap card for each $person:
<div class="container">
<div class="row">
<?php foreach ($persons as $person): ?>
<div class="card col-md-3 m-1">
<img class="card-img-top" src="<?=person['img_src']?>" alt="<?=$person['name']?>">
<div class="card-block">
<h4 class="card-title"><?=$person['name']?></h4>
<p class="card-text"><?=$person['info']?></p>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
Everything works fine when I remove m-1 class, but as soon as I add m-1 class, margin causes the last div to go to next line. I think lack of space causes this problem. How can I fix this problem? How to have margin between divs without the last div going to the next line?
You should have a separate div for the card since it's display:flex. Also, just use my-1 for margin-top and margin-bottom so that x-axis space is not effected...
<div class="container">
<div class="row">
<?php foreach ($persons as $person): ?>
<div class="col-md-3 my-1">
<div class="card">
<img class="card-img-top" src="<?=person['img_src']?>" alt="<?=$person['name']?>">
<div class="card-block">
<h4 class="card-title"><?=$person['name']?></h4>
<p class="card-text"><?=$person['info']?></p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
https://www.codeply.com/go/78AmkbWrLi
The easiest solution would be to just put another div inside the col, which applies the margin:
<div class="container">
<div class="row">
<?php foreach ($persons as $person): ?>
<div class="card col-md-3">
<div class="m-1"> <!-- NEW -->
<img class="card-img-top" src="<?=person['img_src']?>" alt="<?=$person['name']?>">
<div class="card-block">
<h4 class="card-title"><?=$person['name']?></h4>
<p class="card-text"><?=$person['info']?></p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
Or if you don't want to add another div, just add the m-1 class to the card-block.
i am using a main fours divs first div has class ad1, second and third div has class ad2 and then last div has class ad3...
i want to display 4 images from database
How to do it through while loop, please help, Thanks :)
here is html code and the php code....
<div class="col-md-9 hidden-sm hidden-xs">
<div class="col-md-1"></div>
<div class="col-md-2">
<div class="ad1">
<img src="" alt="">
</div>
</div>
<div class="col-md-2">
<div class="ad2">
<img src="" alt="">
</div>
</div>
<div class="col-md-2">
<div class="ad2">
<img src="" alt="">
</div>
</div>
<div class="col-md-5">
<div class="ad3">
<img src="" alt="">
</div>
</div>
</div>
php code is
<?php
$query = "SELECT * FROM headerimages limit 4";
$result = mysqli_query($con, $query) or die(mysqli_error($query));
while ($row = mysqli_fetch_array($result))
{?>
<?php
}
?>
First of all I recommend to use pdo database driver.
In your code the fast fix will be to assign result to array and simply echo it in the view.
$result = array();
while ($row = mysqli_fetch_array($result))
{
$result[]=$row['img'];
}
and in view echo it
<div class="col-md-9 hidden-sm hidden-xs">
<div class="col-md-1"></div>
<div class="col-md-2">
<div class="ad1">
<img src="<?=$result[0]?>" alt="">
</div>
</div>
<div class="col-md-2">
<div class="ad2">
<img src="<?=$result[1]?>" alt="">
</div>
</div>
<div class="col-md-2">
<div class="ad2">
<img src="<?=$result[2]?>" alt="">
</div>
</div>
<div class="col-md-5">
<div class="ad3">
<img src="<?=$result[3]?>" alt="">
</div>
</div>
</div>