use_page_numbers in codeigniter pagination class? - codeigniter

I have a problem with using use_page_numbers config set to true in my pagination class!
When I click on the link of page 2, the number of rows it retrieves from database is correct, but the problem is that:
the first row of page 2 is the third row of page one ! It means that page 2 starts with the same row from the database which has been retrieved in the first page in the third row. for example :
Page 1: 10, 11, 12, 13, 14
Page 2: 12, 13, 14, 15, 16
and of course the page 3 starts from the second row of page 2 :
Page 3: 13, 14, 15, 16, 17
This is the code I have :
function get_brands_list($options = array())
{
//Pagination config
$config['base_url'] = base_url() . 'admin/brands/page/';
$config['total_rows'] = $this->db->get('mg_brands')->num_rows();
$config['per_page'] = 5;
$config['num_links'] = 4;
$config['uri_segment'] = 4;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$offset = $this->uri->segment(4, 0);
$this->db->order_by('brand_Sort', 'ASC');
$query = $this->db->get('mg_brands', $config['per_page'], $offset);
if(isset($options['brand_Id']) || isset($options['brand_Name']))
return $query->row(0);
return $query->result();
}

You have a problem in calculation of offset variable.... Try this one:
$page_num = $this->uri->segment(4, 0);
$offset = ($page_num - 1) * $config['per_page'];

Related

add current date to chartjs with momentjs

i need help please with this code :
dump missing date in data for chartjs
my table for example with values:
bonus date
5 : 18-04-2020
10 : 19-04-2020
0 : 20-04-2020
0 : 21-04-2020
55 : 22-04-2020
44 : 23-04-2020
30 : 24-04-2020
i get last 7 days date in database, chartjs display all dates, but i want in chart not to display 30 : 24-04-2020 last date but i want to display 0: 25-04-2020 if not exists in database because user not have any bonus yet today.. i think need to add 1 day in last date in chartjs ? or in database query ?
my code :
var graphData = [55, 10, 0, 0, 55, 44, 30],
labels = ["18-04-2020", "19-04-2020", "20-04-2020", "21-04-2020", "22-04-2020", "23-04-2020", "24-04-2020"];
for (var i = 0; i < labels.length; i++) {
//make sure we are not checking the last date in the labels array
if (i + 1 < labels.length) {
var date1 = moment(labels[i], "DD-MM-YYYY");
var date2 = moment(labels[i + 1], "DD-MM-YYYY");
//if the current date +1 is not the same as it's next neighbor we have to add in a new one
if (!date1.add(1, "days").isSame(date2)) {
//add the label
labels.splice(i + 1, 0, date1.format("DD-MM-YYYY"));
//add the data
graphData.splice(i + 1, 0, 0);
}
}
}
var ctx = document.getElementById("chart").getContext("2d");
var data = {
labels:labels,
datasets: [{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.5)",
strokeColor: "rgba(220,220,220,0.8)",
highlightFill: "rgba(220,220,220,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data: graphData
}]
};
var myLineChart = new Chart(ctx).Line(data);

AMCharts - unable to get Line graph to draw

I have a line graph drawing using data created like so:
for (var i = 1; i < 366; i++) {
visits += Math.round((Math.random() < 0.5 ? 1 : -1) * Math.random() * 10);
data.push({ date: new Date(2018, 0, i), value: visits });
}
The rest of the options set look like:
__this._chart.data = data;
var dateAxis = __this._chart.xAxes.push(new am4charts.DateAxis());
dateAxis.renderer.grid.template.location = 0;
dateAxis.renderer.axisFills.template.disabled = true;
dateAxis.renderer.ticks.template.disabled = true;
var valueAxis = __this._chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.tooltip.disabled = true;
valueAxis.renderer.minWidth = 35;
valueAxis.renderer.axisFills.template.disabled = true;
valueAxis.renderer.ticks.template.disabled = true;
var series = __this._chart.series.push(new am4charts.LineSeries());
series.dataFields.dateX = "date";
series.dataFields.valueY = "value";
This draws a random line for the whole year and it works.
We dont want to show every day, we want to show monthly data. So I have data that when processed shows up in the form:
{
category: Mon Oct 31 2016 20:00:00 GMT-0400 (Eastern Daylight Time)
column-1: 50
}
Theres only 9 of them and they cover up to January 2019, so there would be huge gaps between the data points. the object name of category is different to date but I set the series' dateX = "category".
So my question is, can the line graph be used to do monthly data where there could be gaps in the data?
If so, how do I get it to work? I use the rest of the options the exact same as the test that is working, except for hte changed values of series' dateX and valueY.

Multiple Pagination by Codeigniter

How to implement more than one pagination , say two or three on the same page showing different records using Codeigniter. I had tried using the default pagination library but it does not work out.
Would appreciate if this question is answered in detail and using simple explanation(I being a mediocre Programmer)
I haven't done this before, but I guess you could create n-different $configs and use the $this->pagination->initialize(); each time to initialize the paginations.
Something like this (not tested):
$this->load->library('pagination');
$config1['base_url'] = 'http://example.com/index.php/test/page/';
$config1['total_rows'] = 200;
$config1['per_page'] = 20;
$this->pagination->initialize($config1);
echo $this->pagination->create_links();
$config2['base_url'] = 'http://example.com/index.php/test/page/';
$config2['total_rows'] = 200;
$config2['per_page'] = 20;
$this->pagination->initialize($config2);
echo $this->pagination->create_links();
$config3['base_url'] = 'http://example.com/index.php/test/page/';
$config3['total_rows'] = 200;
$config3['per_page'] = 20;
$this->pagination->initialize($config3);
echo $this->pagination->create_links();
Have you checked it?

Multiple datepicker: pass dates from php to view

currently i using multiple datepicker (http://keith-wood.name/datepick.html). I need to pass dates from MySQL table with PHP (reservations) to calendar and change CSS style for show state.
occupied - red
pending - yellow
free - grey
preview on another site: http://www.chata-vysocina.eu/en/rezervace/
Anyone have some tips how to do that?
Thank you,
Tomas
Ok, i resolved my problem with following lines.
<script>
var dates = [
[2013, 12, 24],
[2013, 12, 25]
];
var today = new Date();
$('#reserve').multiDatesPicker({
firstDay: 1,
numberOfMonths: 4,
dateFormat: "dd-mm-yy",
altField: '#dates',
minDate: 0,
beforeShowDay: function (date){
var year = date.getFullYear(), month = date.getMonth(), day = date.getDate();
// see if the current date should be highlighted
for (var i=0; i < dates.length; ++i)
if (year == dates[i][0] && month == dates[i][1] - 1 && day == dates[i][2])
return [false, 'booked'];
return [false];
}
});
</script>

choose random value only once

My page loads a random background image every time it loads:
<?php
$input = array(1, 2, 3, 4, 5, 6, 7, 8);
$num = array_rand($input, 1);
$bg = "img/bg" . $num . ".jpg";
?>
But I want it to do that only once. I want the image to remain the same after a visitor submits a form, for example, thereby reloading the page.
I've tried if($bg=NULL) etc, but to no avail - I guess $bg becomes null again every time the page reloads.
Many thanks in advance!
You can use Session variable or cookies if is not set, you choose a background, if is set, you do nothing
Got it (thanks to Ricardo):
<?php
session_start();
if (!isset($_SESSION['num'])) {
$input = array(1, 2, 3, 4, 5, 6, 7, 8);
$_SESSION['num'] = array_rand($input, 1);
}
$bg = "img/bg" . $_SESSION['num'] . ".jpg";
?>

Resources