Single Item Slider using Codeigniter (Autoplay)
Single Item Slider using Codeigniter without javascript (Autoplay)
Database Queries :
CREATE DATABASE IF NOT EXISTS `slider` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `slider`;
CREATE TABLE `slider` (
`s_id` int(11) NOT NULL,
`s_title` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `slider` (`s_id`, `s_title`) VALUES
(1, 'Rose'),
(2, 'Tulips'),
(3, 'Lotus');
ALTER TABLE `slider`
ADD PRIMARY KEY (`s_id`);
ALTER TABLE `slider`
MODIFY `s_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
COMMIT;
Welcome.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('Slider_model');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->library("pagination");
$this->load->helper('security');
}
public function index()
{
$data['title'] = 'Single Item Slider';
$data['description'] = 'Single Item Slider using Codeigniter';
$data['slider'] = $this->Slider_model->getslider();
$this->load->view('welcome_message', $data);
}
}
Slider_model.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Slider_model extends CI_Model
{
function getslider()
{
return $this->db->select('*')
->from('slider')
->get()->result();
}
}
welcome_message.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?php echo $title; ?></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<style>
.simage{
height: 250px;
}
</style>
</head>
<body>
<div id="container">
<div class="col-md-3 col-xs-12 col-sm-12 widget-border">
<h1>Single Item Slider</h1>
<div id="carousel-1" class="carousel slide slide-carousel" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators" style="display:none">
<li data-target="#carousel-1" data-slide-to="0" class="active"></li>
<li data-target="#carousel-1" data-slide-to="1"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<?php $cnt=0; foreach ($slider as $l_row):$cnt+=1;?>
<div class="item <?php if($cnt==1) {echo 'active'; }?>">
<div class="img">
<img class="simage" alt="<?php echo $l_row->s_title; ?>" src="<?php echo base_url(); ?>template/images/slider_<?php echo $l_row->s_id; ?>_1.jpg">
</div>
<h3 class="post-title text-center"> <?php echo $l_row->s_title; ?></h3>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="clearfix"></div>
</div>
</body>
</html>
Database.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'slider',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Config.php
Add this:
$config['base_url'] = 'http://localhost/Demo';
Comments
Post a Comment