Pagination for a table contents in yii - php

I'm using Yii application. In that how to give pagination to a table contents (not using cgridview).
In view,
<table data-provides="rowlink" data-page-size="20" data-filter="#mailbox_search" class="table toggle-square default footable-loaded footable line-content" id="mailbox_table">
<thead>
<tr>
<th></th>
<th data-hide="phone,tablet">From</th>
<th>Subject</th>
<th data-hide="phone" class="footable-last-column">Date</th>
</tr>
</thead>
<tbody>
<?php
foreach ($model as $item) {
if ($item->fromuser->usertypeid === '0') {
$name = $item->fromuser->username;
} else if ($item->fromuser->usertypeid === '1') {
$student = Student::model()->findByPk($item->fromuser->userid);
$name = $student->student_admissionno . " - " . $student->student_firstname . " " . $student->student_middlename . " " . $student->student_lastname;
} else if ($item->fromuser->usertypeid === '3') {
$guardian = Guardian::model()->findByPk($item->fromuser->userid);
$name = $guardian->guardian_name;
} else {
$employee = Employeemaster::model()->findByPk($item->fromuser->userid);
$name = $employee->employee_code . " - " . $employee->employee_firstname . " " . $employee->employee_middlename . " " . $employee->employee_lastname;
}
if ($item->email_status == 1)
echo '<tr id="' . $item->emailid . '" class="unreaded rowlink" style="display: table-row;">';
else
echo '<tr id="' . $item->emailid . '" class="rowlink" style="display: table-row;">';
echo '<td class="nolink footable-first-column">';
echo '<span class="footable-toggle"></span>';
echo '<input type="checkbox" class="mbox_msg_select" name="msg_sel"></td>';
echo '</span></td>';
echo '<td>' . $name . '</td>';
echo '<td>' . $item->email_subject . '</td>';
$originalDate = $item->time;
$newDate = date("Y-M-d H:i:s", strtotime($originalDate));
echo '<td class="footable-last-column">' . $newDate . '</td></tr>';
}
?>
</tbody>
</table>
<div class="main-detail-con" style="width:700px;">
<div style="width:700px; padding-left: 0px;" class="listing-center-numbers">
<?php
$this->widget('CLinkPager', array(
'pages' => $pages,
'currentPage' => $pages->getCurrentPage(),
'itemCount' => $item_count,
'pageSize' => $page_size,
'maxButtonCount' => 5,
));
?>
</div>
</div>
<div class="clear"></div>
In Controller,
public function actionEmail() {
$criteria = new CDbCriteria;
$criteria->order = 'time DESC';
$criteria->condition = 'to_userid = :id';
$criteria->params = array(':id' => Yii::app()->user->id);
$criteria->addCondition('t.email_status= "2" OR
t.email_status= "1"');
$item_count = Email::model()->count($criteria);
$model = Email::model()->findAll($criteria);
$pages = new CPagination($item_count);
$pages->setPageSize(Yii::app()->params['listPerPage']);
$pages->applyLimit($criteria);
$this->render('inbox', array(
'model' => $model,
'item_count' => $item_count,
'page_size' => Yii::app()->params['listPerPage'],
'items_count' => $item_count,
'pages' => $pages,
));
}
In main/config.php
'params' => array(
'listPerPage'=> 2,//default pagination size
),
Output is,
The page size (I am giving 2 for per page) is not working by using this code. Please help me...

First of all define a new params in config/main.php, something like:
'params'=>array(
// this is used in contact page
'adminEmail'=>'webmaster#example.com',
'listPerPage'=> 10,//default pagination size
),
Now, modify your controller's action like:
public function actionOutbox() {
$criteria = new CDbCriteria;
$criteria->condition = 'from_userid = :id';
$criteria->order = 'time DESC';
$criteria->params = array (':id'=>Yii::app()->user->id);
$item_count = Email::model()->count($criteria);
$model = Email::model()->findAll($criteria);
$pages = new CPagination($item_count);
$pages->setPageSize(Yii::app()->params['listPerPage']);
$pages->applyLimit($criteria);
$this->render('outbox', array(
'model' => $model,
'item_count'=>$item_count,
'page_size'=>Yii::app()->params['listPerPage'],
'items_count'=>$item_count,
'pages'=>$pages,
));
}
Then in your view after foreach loop add CLinkPager widget, like:
<?php
$this->widget('CLinkPager', array(
'currentPage' => $pages->getCurrentPage(),
'itemCount' => $item_count,
'pageSize'=> $page_size,
'maxButtonCount' => 5,
//'nextPageLabel' =>'My text >',
'htmlOptions' => array('class'=>'pages'),
));
?>
Thats all you need to do, you might have to do some css changes though, hope that helps :)

Related

Match column and row, then print data

I am having two set off arrays, first array is holding data about colors, second about dimensions.
$colors= array(
"27" => "RAL 9002",
"255" => "RAL 9006",
"341" => "RAL 8019",
"286" => "RAL 7016",
"141" => "RAL 3009",
"171" => "RAL 6028",
"121" => "RAL 8004",
"221" => "RAL 5010",
"101" => "RAL 3000",
"273" => "RAL 9007",);
$dimensions = array
(
array(0.3,1245),
array(0.35,1245),
array(0.40,1100),
array(0.45,1245),
array(0.50,1245),
array(0.60,1245),
array(0.70,1245),
);
Values above are used for queries. I wanted to make an array which will hold data, and later in comparison will print data. Query can return result NULL
foreach($colors as $key => $value)
{
//print "Boja $key . <br>";
foreach($dimensions as $data )
{
//print "Debljina $data[0], Sirina $data[1] Boja $key <br>";
$sql = "SELECT Debljina, Sirina, sum(Kolicina) as suma
FROM jos_ib_repromaterijali WHERE Debljina = '$data[0]' AND Sirina = '$data[1]' AND Boja = '$key'";
$q = $conn -> query($sql);
$vrijednosti = array();
while($r=$q->fetch()) {
$debljina = $r['Debljina'];
$sirina = $r['Sirina'];
$kolicina = $r['suma'];
$vrijednosti[] = $debljina . $sirina . $kod . $kolicina;
}
}
}
Once I get results, I create html table
<div class="col-lg-6">
<table class="table table-bordered">
<thead>
<tr>
<th><?php echo "Dimenzije"; ?> </th>
<?php foreach($colors as $boja) { ?>
<th><?php echo $boja; ?> </th>
<?php } ?>
</tr>
</thead>
<tbody>
<?php foreach($dimensions as $dim) {
?>
<tr>
<td><?php echo $dim[0] . ' X ' . $dim[1]; ?> </td>
<td><?php
if (isset($vrijednosti[$dim[0] . $dim[1]])) {
echo "asdas";
}
else {
echo "error";
}
?> </td>
</tr>
<?php }
?>
</tbody>
</table>
Table print headers and dimensions as it should, I am having trouble in matching rows with column. If someone give me an advice it would be appreciated.
Query can give result NULL; if that is result It should print 0 below color for specific row.

Embedded youtube videos are cutting my messages from chat

I am with some problems in my php script when I try to envoke embedded youtube videos when reply, or send a message.
My php script is:
<?php
if($_GET['u'] != $user) {
$messages = addslashes($_POST['message']);
$messages = preg_replace_callback('#(?:https?://\S+)|(?:www.\S+)|(?:\S+\.\S+)#', function($arr)
{
if(strpos($arr[0], 'http') !== 0)
{
$arr[0] = 'http://' . $arr[0];
}
$url = parse_url($arr[0]);
// images
if(preg_match('#\.(png|jpg|gif)$#', $url['path']))
{
echo '<img src="'. $arr[0] . '" />';
}
// youtube
if(in_array($url['host'], array('www.youtube.com', 'youtube.com'))
&& $url['path'] == '/watch'
&& isset($url['query']))
{
parse_str($url['query'], $query);
return sprintf('<iframe width="560" height="315" src="http://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>', $query['v']);
}
//links
return nl2br(sprintf('%1$s ', $arr[0]));
}, $messages);
$to = $_GET['u'];
$selPictureMsg = "SELECT * FROM users WHERE username = '$user'";
$result = mysqli_query($sql, $selPictureMsg);
$msgPicRow = mysqli_fetch_assoc($result);
$selPictureMsg11 = "SELECT * FROM users WHERE username = '$to'";
$result11 = mysqli_query($sql, $selPictureMsg11);
$msgPicRow11 = mysqli_fetch_assoc($result11);
$user_pic = $msgPicRow['profile'];
$receiver_pic = $msgPicRow11['profile'];
if(isset($_POST['msgSend'])) {
if(strlen($messages) <= 1) {
echo "<div class='error'>Sorry! Your message is too small. It needs to be more than 1 character.</div>";
} else {
$insMsg = "INSERT INTO messages VALUES('','$user','$to','$messages','0','$user_pic','$receiver_pic', NOW())";
$sql->query($insMsg);
echo "<div class='success'>Your message has been sent to ".$to." successfully.</div><br />";
}
}
$selmsg1 = "SELECT * FROM messages WHERE (to_user='$user' AND from_user='$to') OR (to_user ='$to' AND from_user='$user') ORDER BY date DESC";
$resultmsg1 = $sql->query($selmsg1);
$rownum = mysqli_num_rows($resultmsg1);
if($rownum > 0) {
$i = '';
echo "<table>
<tr class='chat'>";
while($assocMsg = mysqli_fetch_assoc($resultmsg1)) {
if($user == $_GET['from'] || $user != $assocMsg['to_user']) {
$smilies = array(
':|' => 'bored',
':-|' => 'bored',
':-o' => 'scared',
':-O' => 'scared',
':o' => 'scared',
':O' => 'scared',
';)' => 'wink',
';-)' => 'wink',
':p' => 'tongue',
':-p' => 'tongue',
':P' => 'tongue',
':-P' => 'tongue',
':D' => 'happy',
':-D' => 'happy',
';P' => 'wink-tongue',
';-P' => 'wink-tongue',
':)' => 'smile',
':-)' => 'smile',
':(' => 'sad',
':-(' => 'sad',
'<3' => 'heart',
':*' => 'kiss',
'*_*' => 'in-love',
';(' => 'crying',
':a' => 'angry',
':#' => 'rage',
':3' => 'normal-kiss',
'><' => 'shy',
';D' => 'happily',
';-D' => 'happily',
':$' => 'blushing',
'o_o"' => 'dont-get',
'XD' => 'laugh',
'*lookdown*' => 'look-down',
'*lookup*' => 'look-up',
'*lookleft*' => 'look-left',
'*lookright*' => 'look-right',
'$_$' => 'money',
'$.$' => 'money',
'#_#' => 'nerd',
'#.#' => 'nerd',
'*vomit*' => 'vomit'
);
$replace = array();
foreach ($smilies as $smiley => $imgName)
{
array_push($replace, '<img src="images/emoticons/'.$imgName.'.png" alt="'.$smiley.'" />');
}
$assocMsg["message"] = str_replace(array_keys($smilies), $replace, $assocMsg["message"]);
echo "
<div style='width:100%; max-height: 300px; overflow: auto;'>
<td><a href='profile.php?u=".$assocMsg['from_user']."'><img src='".$assocMsg['user_picture']."' width='auto' height='70px' /></a></td>
<td>".$assocMsg['message']."<br />".$video."</td>
</tr>
<tr>
<td colspan='5'><i>".$assocMsg['date']."</i></td>
</div>
";
$i++;
if($i % 1 == 0) {
echo "</tr><tr class='chat'>";
}
} else {
echo "
<div style='width:100%; max-height: 300px; overflow: auto;'>
<td><a href='profile.php?u=".$assocMsg['to_user']."<img src='".$assocMsg['friend_picture']."' width='auto' height='70px' /></a></td>
<td>".$messages."</td>
</tr>
<tr>
<td colspan='5'><i>".$assocMsg['date']."</i></td>
</div>
";
$i++;
if($i % 1 == 0) {
echo "</tr><tr class='chat'>";
}
}
}
echo "</tr>
</table><hr />";
} else {
echo "You don't have any conversations with $to<br /><hr />";
}
?>
Now I will show you in images the result before and after embedded youtube videos.
Before:
Before embedded youtube video
After:
After embedded youtube video
I don't know why is cutting the other messages, which are stored in database, and only shows the video, without showing the other messages as well.
In here return sprintf('<iframe width="560" height="315" src="http://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>', $query['v']); , I tried with echo sprintf(....) as well but with echo is not storing on database.
And if I let the return it shows what image After: is showing.
So, what I want is to the embedded youtube video, appears as long the text you send the video + showing the older messages from the chat.

I want to display subject for specific class i.e A or B but current I display only A?

I try to display every each data on the specific td, but I dont know where to fix my code. Please check the screenshop below to understand the clearly problems. Please any help to solve this problems.
<table class="table table-hover table-bordered ">
<tr><th>Day</th><th colspan="2">08:00-08:40</th><th colspan="2">8:40-09:20</th><th colspan="2">09:20-10:00</th><th>10:00-10:15</th><th colspan="2">10:15-10:55</th><th colspan="2">10:55-11:35</th><th colspan="2">11:35-12:15</th><th>12:15-01:15</th><th colspan="2">01:15-01:55</th><th colspan="2">01:55-02:35</th></tr>
<?php
$timesVariants = array("08:00-08:40", "08:40-09:20", "09:20-10:00", "10:00-10:15", "10:15-10:55", "10:55-11:35", "11:35-12:15", "12:15-01:15", "01:15-01:55","01:55-02:35");
$sqlquery = "SELECT * FROM timetable,classroom,subprogramme WHERE classroom.classid = timetable.classid AND subprogramme.subid = timetable.subid";
$res = $connect->query($sqlquery);
$classes = array();
while($row = $res->fetch_assoc()) {
$classes[$row['day']][$row['tid']][$row['time']] = array('courseid'=> $row['cid'], 'classname' => $row['classname'], 'subname' => $row['subname']);
}
//This is a loop
foreach($classes as $day => $daySchedule) {
foreach($daySchedule as $teacher) {
print '<tr>';
print "<td>$day</td>";
foreach($timesVariants as $time) {
if (empty($teacher[$time])){
print "<td>*</td><td>*</td>";
}
else{
print '<td>' . $teacher[$time]['courseid'] . '</td><td>' . $teacher[$time]['subname'] . ''. $teacher[$time]['classname'] . '</td>';
}
}
print '</tr>';
}
}
?>
</table>
Output
Results display on the webpage
You trouble is in the GROUP BY. MySql have no strict restrictions (by default) that each column should use aggregation function, so the result is the first row, instead of complicating SQL use PHP, your result seems not to be huge, so another loop will not affect performance:
$timesVariants = array("08:00-08:40", "08:40-09:20", "09:20-10:00", "10:00-10:15", "10:15-10:55", "10:55-11:35", "11:35-12:15", "12:15-1:15", "01:15-01:55","01:55-02:35");
$sqlquery = "SELECT * FROM timetable";
$classes = array();
while($row = $res->fetch_assoc()) {
$classes[$row['day']][$row['tid']][$row['time']] = array('subject'=> $row['subject'], 'class' => $row['class'], 'progid' => $row['progid']);
}
//This is a loop
foreach($classes as $day => $daySchedule) {
foreach($daySchedule as $teacher) {
print '<tr>';
print "<td>$day</td>";
foreach($timesVariants as $time) {
if (empty($teacher[$time]))
print "<td>None</td><td>None</td>";
else
print '<td>' . $teacher[$time]['subject'] . '</td><td>' . $teacher[$time]['class'] . '</td>';
}
print '</tr>';
}
}
<?php
if(isset($_POST["tid"])){
$tid = $connect->real_escape_string($_POST["tid"]);
$sqlquery = "SELECT * FROM timetable,classroom,subprogramme WHERE classroom.classid = timetable.classid AND subprogramme.subid = timetable.subid AND timetable.tid = ".$tid." ORDER BY timetable.timid ASC";
$res = $connect->query($sqlquery);
if($res->num_rows > 0){
?>
<table class="table table-bordered table-striped">
<tr><th>Day</th><th colspan="2">8:00-8:40</th><th colspan="2">8:40-9:20</th><th colspan="2">9:20-10:00</th><th colspan="2">10:00-10:15</th><th colspan="2">10:15-10:55</th><th colspan="2">10:55-11:35</th><th colspan="2">11:35-12:15</th><th colspan="2">12:15-1:15</th><th colspan="2">1:15-1:55</th><th colspan="2">1:55-2:35</th></tr>
<?php
$timesVariants = array("8:00-8:40", "8:40-9:20", "9:20-10:00", "10:00-10:15", "10:15-10:55", "10:55-11:35", "11:35-12:15", "12:15-01:15", "1:15-1:55","1:55-2:35");
$classes = array();
while($row = $res->fetch_assoc()) {
$classes[$row['day']][$row['tid']][$row['time']] = array('courseid'=> $row['cid'], 'classname' => $row['classname'], 'subname' => $row['subname']);
}
//This is a loop
foreach($classes as $day => $daySchedule) {
foreach($daySchedule as $teacher) {
print '<tr>';
print "<td>$day</td>";
foreach($timesVariants as $time) {
if (empty($teacher[$time])){
print "<td>*</td><td>*</td>";
}
else{
print '<td>' . $teacher[$time]['courseid'] . '</td><td>' . $teacher[$time]['subname'] . ''. $teacher[$time]['classname'] . '</td>';
}
}
print '</tr>';
}
}
?>
</table>
<?php
}
else{ print "<div class='alert alert-danger col-md-4'><span class='glyphicon glyphicon-remove'></span> Not yet set timetable</div>"; }
} ?>
</div>
The problems was on td I forgot to put colspan = 2, and other problem on sql query I forgot to inner join the tables in order to get all right that i want to display on the page.

The .jpg is being changed to _jpg for an image name from the database

I have a script here that somehow changes the .jpg to _jpg.
<?php
global $Sys;
//echo $Sys->Auth->chkAuth();
if(isset($_POST['update_slider']))
{
unset($_POST['update_slider']);
$post = $_POST;
unset($_POST);
foreach($post as $name => $value)
{
$value = (is_numeric($value)) ? $value : intval($value);
$result = $Sys->db->query("UPDATE dj_photo SET slider_status = $value WHERE name = $name");
}
if($result->affected_rows != 0)
{
$Sys->Template->setAlerts($result->affected_rows . ' images were added to the image slider.');
}
else
{
$Sys->Template->setAlerts('No images were added to the slider.', 'error');
}
}
?>
<div id="webCfg">
<h2>Website Configuration</h2>
<?php
global $Sys;
$alerts = $Sys->Template->getAlerts();
if ($alerts != '') { echo '<div><ul class="alerts">' . $alerts . '</ul></div>'; }
$result = $Sys->db->query('SELECT * FROM dj_photo ORDER BY group_name ASC');
?>
<form action="" method="post">
<table cellpadding="1" cellspacing="0" id="webCfgTbl">
<tr><td class="label"><label for="submit"></label></td><td class="content"><div class="row submitrow"><input type="submit" id="submit" name="update_slider" class="submit" value="Update Slider" /></div></td></tr>
<tr>
<?php
$i = 1;
while($slider = $result->fetch_object())
{
if($slider->slider_status == 1)
{
$add = 'selected';
}
else
{
$remove = 'selected';
}
if(($i % 6) == 0)
{
echo " Slider Name: " . $slider->name;
echo '<td><div class="adm_slider_pics"><img style="width:180px;height:120px;" alt="' . ucfirst($slider->name) . '" src="../photogallery/' . $slider->img_group . '/' . $slider->name . '" title="' . ucfirst($slider->title) . '" /></a></td><td class="content"><select name="' . $slider->name . '"><option value="1" ' . $add . '>Add</option><option value="0" ' . $remove . '>Remove</option></select></div></td></tr><tr>';
}
else
{
echo " Slider Name: " . $slider->name;
echo '<td><div class="adm_slider_pics"><img style="width:180px;height:120px;" alt="' . ucfirst($slider->name) . '" src="../photogallery/' . $slider->img_group . '/' . $slider->name . '" title="' . ucfirst($slider->title) . '" /></a></td><td class="content"><select name="' . $slider->name . '"><option value="1" ' . $add . '>Add</option><option value="0" ' . $remove . '>Remove</option></select></div></td>';
}
$i++;
}
?>
<tr><td class="label"><label for="submit"></label></td><td class="content"><div class="row submitrow"><input type="submit" id="submit" name="update_slider" class="submit" value="Update Slider" /></div></td></tr>
</tr></table>
</form>
</div>
echo " Slider Name: " . $slider->name; prints this out:
Slider Name: DSCF3727.jpg Slider Name: DSCF3687.jpg Slider Name: DSCF3744.jpg Slider Name: DSCF4070.jpg Slider Name: DSCF4071.jpg Slider Name: DSCF4073.jpg Slider Name: 10245379_229236400605097_7329379469957650735_n.jpg Slider Name: 10314007_229236253938445_8056225029697636541_n.jpg Slider Name: DSCF3618.jpg Slider Name: 10550825_261238134071590_1715454340087601479_n.jpg Slider Name: 1551739_261238150738255_2482363522486143465_n.jpg Slider Name: 10626882_284760908385979_3153917771920003400_n.jpg Slider Name: 10689730_284760921719311_8515870397004989019_n.jpg Slider Name: DSCF3384.jpg Slider Name: DSCF3382.jpg Slider Name: biker.jpg Slider Name: 10410927_255245578004179_6557207701489592736_n.jpg Slider Name: 10400847_255245548004182_5319163275713658480_n.jpg Slider Name: 111111.jpg Slider Name: DSCF3013.jpg Slider Name: DSCF4040.jpg Slider Name: 1011255_238047056390698_6002378516798338793_n.jpg Slider Name: 10373785_238048733057197_8255990183542589096_n.jpg Slider Name: 10383572_238047003057370_1041466926744898970_n.jpg Slider Name: DSCF4047.jpg Slider Name: DSCF4051.jpg Slider Name: DSCF4109.jpg Slider Name: DSCF4121.jpg Slider Name: DSCF4136.jpg Slider Name: DSCF4029.jpg Slider Name: Rancho-las-lomas-wedding-DJ.jpg Slider Name: webtest.jpg
<?php
global $Sys;
//echo $Sys->Auth->chkAuth();
if(isset($_POST['update_slider']))
{
print_r($_POST);
exit;
unset($_POST['update_slider']);
$post = $_POST;
unset($_POST);
foreach($post as $name => $value)
I add print_r($_POST); after the if and before exit; and get this:
Array ( [update_slider] => Update Slider [DSCF3727_jpg] => 0 [DSCF3687_jpg] => 0 [DSCF3744_jpg] => 0 [DSCF4070_jpg] => 0 [DSCF4071_jpg] => 0 [DSCF4073_jpg] => 0 [10245379_229236400605097_7329379469957650735_n_jpg] => 0 [10314007_229236253938445_8056225029697636541_n_jpg] => 0 [DSCF3618_jpg] => 0 [10550825_261238134071590_1715454340087601479_n_jpg] => 0 [1551739_261238150738255_2482363522486143465_n_jpg] => 0 [10626882_284760908385979_3153917771920003400_n_jpg] => 0 [10689730_284760921719311_8515870397004989019_n_jpg] => 0 [DSCF3384_jpg] => 0 [DSCF3382_jpg] => 0 [biker_jpg] => 0 [10410927_255245578004179_6557207701489592736_n_jpg] => 0 [10400847_255245548004182_5319163275713658480_n_jpg] => 0 [111111_jpg] => 0 [DSCF3013_jpg] => 0 [DSCF4040_jpg] => 0 [1011255_238047056390698_6002378516798338793_n_jpg] => 0 [10373785_238048733057197_8255990183542589096_n_jpg] => 0 [10383572_238047003057370_1041466926744898970_n_jpg] => 0 [DSCF4047_jpg] => 0 [DSCF4051_jpg] => 0 [DSCF4109_jpg] => 0 [DSCF4121_jpg] => 0 [DSCF4136_jpg] => 0 [DSCF4029_jpg] => 0 [Rancho-las-lomas-wedding-DJ_jpg] => 0 [webtest_jpg] => 0 ) DSCF3727_jpg
I am stumped on this. Any help is appreciated.
For anyone wondering how to fix this PHP problem (Not Mysqli problem):
Old:
if(isset($_POST['update_slider']))
{
unset($_POST['update_slider']);
$post = $_POST;
unset($_POST);
foreach($post as $name => $value)
{
$value = (is_numeric($value)) ? $value : intval($value);
$result = $Sys->db->query("UPDATE dj_photo SET slider_status = $value WHERE name = $name");
}
if($result->affected_rows != 0)
{
$Sys->Template->setAlerts($result->affected_rows . ' images were added to the image slider.');
}
else
{
$Sys->Template->setAlerts('No images were added to the slider.', 'error');
}
}
New:
if(isset($_POST['update_slider']))
{
unset($_POST['update_slider']);
$post = $_POST;
unset($_POST);
$search = array('_jpg', '_jpeg', '_png', '_bmp', '_gif');
$replace = array('.jpg', '.jpeg', '.png', '.bmp', '.gif');
foreach($post as $name => $value)
{
$column = str_replace($search, $replace, $name);
$value = (is_numeric($value)) ? $value : intval($value);
$result = $Sys->db->query("UPDATE dj_photo SET slider_status = '" . $value . "' WHERE name = '" . $column . "'");
}
if($result)
{
$Sys->Template->setAlerts($result->mysqli_affected_rows . ' images were added to the image slider.');
}
else
{
$Sys->Template->setAlerts('No images were added to the slider.', 'error');
}
}

Pagination for a table in yii

I'm using Yii application. In that how to give pagination to a table contents( not using cgridview).
config/main.php
'params'=>array(
'adminEmail'=>'webmaster#example.com',
'listPerPage'=> 10,//default pagination size
),
In Controller,
public function actionOutbox() {
$criteria = new CDbCriteria;
$criteria->condition = 'from_userid = :id';
$criteria->order = 'time DESC';
$criteria->params = array (':id'=>Yii::app()->user->id);
$item_count = Email::model()->count($criteria);
$model = Email::model()->findAll($criteria);
$pages = new CPagination($item_count);
$pages->setPageSize(Yii::app()->params['listPerPage']);
$pages->applyLimit($criteria);
$this->render('outbox', array(
'model' => $model,
'item_count'=>$item_count,
'page_size'=>Yii::app()->params['listPerPage'],
'items_count'=>$item_count,
'pages'=>$pages,
));
}
In View,
<table data-provides="rowlink" data-page-size="20" data-filter="#mailbox_search" class="table toggle-square default footable-loaded footable" id="mailbox_table">
<thead>
<tr>
<th></th>
<th data-hide="phone,tablet">To</th>
<th>Subject</th>
<th data-hide="phone" class="footable-last-column">Date</th>
</tr>
</thead>
<tbody>
<?php
foreach ($model as $item) {
if ($item->email_status == 1)
echo '<tr id="' . $item->emailid . '" class="unreaded rowlink" style="display: table-row;">';
else
echo '<tr id="' . $item->emailid . '" class="rowlink" style="display: table-row;">';
echo '<td class="nolink footable-first-column">';
echo '<span class="footable-toggle"></span>';
echo '</span></td>';
echo '<td>' . $item->touser->username . '</td>';
echo '<td>' . $item->email_subject . '</td>';
$originalDate = $item->time;
$newDate = date("Y-M-d H:i:s", strtotime($originalDate));
echo '<td class="footable-last-column">' . $newDate . '</td></tr>';
}
?>
</tbody>
</table>
<?php
$this->widget('CLinkPager', array(
'currentPage' => $pages->getCurrentPage(),
'itemCount' => $item_count,
'pageSize'=> $page_size,
'maxButtonCount' => 5,
//'nextPageLabel' =>'My text >',
'htmlOptions' => array('class'=>'pages'),
));
?>
By using this code current page size is not working. Full values from table are displayed. I changed page size from 10 to 2 also, but not working.
What am I doing wrong?
Please help me. Thanks in advance
You use findAll without limit and want that yii understand about pagination?
Use CGridView widget instead it and set pagination in DataProvider (not create separate object of pagination: it not affort to result count).
And please read this topic.
Thanks.

Categories