I can insert data into the database using CodeIgniter and also get the data from the database, but the problem is I can't get the data from date 1-9 (the data is present in the database). After the 9th of the month, the data is retrieved successfully.
Controller:
function display($year=null,$month=null){
if (!$year) {
$year = date('Y');
}
if (!$month) {
$month = date('m');
}
$this->load->model('Calendar_model');
if ($day = $this->input->post('day')) {
$this->Calendar_model->add_calendar_data("$year-$month-$day",$this->input->post('data')
);
}
$this->load->model('calendar_model');
$data['calendar']=$this->calendar_model->generate($year,$month);
$data['viewName']=('Student/s_calendar');
$this->load->view('Student/template',$data);
}
Model:
function get_cal_data($year,$month){
$query=$this->db->select('date,data')->from('student_calender')->like('date',"$year-$month")->get();
$cal_data=array();
foreach($query->result() as $row){
$cal_data[substr($row->date,8,2)]=$row->data;
}
return $cal_data;
}
use this function for your calendar data the codeignitor only picks values past 9 because it compares the two characters in the html page to the two characters of days from your database. any number below 10 does not match because in your database it saves any day below 10 with a zero. use this
function get_calender_data($year,$month)
{
$query = $this->db->select('date, data')->from('calendar')
->like('date',"$year-$month",'after')->get();
$cal_data = array();
foreach ($query->result() as $row) {
if(substr($row->date,8,1)==0)
{
$cal_data[substr($row->date,9,1)] = $row->data;
}
else{
$cal_data[substr($row->date,8,2)] = $row->data;
}
}
return $cal_data;
}
I had the same problem via zend framework finally I got the point that the data in mysql is in this format :
YYYY-MM-DD HH:ii:ss
And my query was in this format :
YYYY-m-d h:i:s
It means for example I hade
2013-01-02 13:02:30
in database and I searched for time between
2013-1-2 13:2:30 and 2013-1-3 13:2:30
which gave me wrong answers.
use vardump and see your values of year and month!
Related
In database i have date,start time and end time.now i want to divided these times into 15 mins difference.IF start time is 4:00 AM and end time is 6:00 AM then these times divided into 4:00 AM-(to)4:15AM min,4:15 AM-4:30 AM etc.
in the below i gave some codes.please help me or give me the procedure should i follow to solved this problem
controllar code:
function fetch_availableime(){
$doctor_id = $this->input->post('doctor_id');
$date = $this->input->post('dates');
$started_time = $this->appointment_model->get_started_time($doctor_id,$date);
$ended_time = $this->appointment_model->get_ended_time($doctor_id,$date);
if ($started_time > $ended_time) {
for ($i=$started_time; $i <$ended_time ; $i++) {
$con_times = date('i:sa',strtotime('+15 minutes',strtotime($started_time)));
echo $con_times;
}
}
}
Model Code:
function get_started_time($doctor_id,$date){
$this->db->select('mstime');
$this->db->from('availability');
$this->db->where('doctor_id',$doctor_id);
$this->db->where('date',$date);
$query = $this->db->get();
return $query->result();
}
function get_ended_time($doctor_id,$date){
$this->db->select('metime');
$this->db->from('availability');
$this->db->where('doctor_id',$doctor_id);
$this->db->where('date',$date);
$query = $this->db->get();
return $query->result();
}
result() returns array of object it is better to use row() for single row then access time with object
return $query->row();
then in controller use
$started_time=$started_time->mstime;
$ended_time=$ended_time->metime;
and for compare two dates you should use strtotime(), for more info see this link
It's a simple update code in a PHP function through a GET call from the front-end(Not sure if this matters), the code is converting a particular time zone value to unix time stamps -
$oldDate = null;
$newDate = null;
$ctr = 0;
$timeStamp = array();
$query= $this->userDatabaseConnection->stmt_init();
$query->prepare("SELECT Timestamp from Transaction INNER JOIN `Order` ON `Order`.TransactionId = Transaction.TransactionId");
$query->execute();
$query->bind_result($tID); //this holds the current time zone values
while($query->fetch()){
$oldDate = $tID;
array_push($timeStamp, $oldDate);
}
$query->close();
foreach($timeStamp as $row){
$newDate = strtotime($row);
$queryUpdate= $this->userDatabaseConnection->stmt_init();
$queryUpdate->prepare("UPDATE `Order` SET OrderDate=? WHERE TransactionId=?");
error_log("ERROR!",0);
$queryUpdate->bind_param('is', $unixTS, $oldTS);
$unixTS = $newDate;
$oldTS = $row;
$queryUpdate->execute();
$queryUpdate->close();
$ctr++;
}
if($ctr == 88){
return true;
}
else{
return false;
}
}
The $ctr variable is returning the total number of rows that need to be updated - which equals to the correct value and thus returns a true to my front end Angular controller.
I tried echo-ing the $newDate and $row values - they seem to be correct too.
But it just does not update my table. Can someone please help me figure out why? Am I missing something here? The error log does show the message in my Apache log - but I can't seem to figure out what's causing it.
newbie here at a small non-profit. I inherited a website written long ago and trying to update it. I need help. This page is to insert hyperlinks to forms for entering monthly data. Until now the website was automatically populated with current month and year hyperlinks. Now it is stuck on April 2014. I don't see anywhere in the Mysql tables or code to add the new months. I believe it may be the 'function getNewMonth($x)' but I don't know why it stopped working. I need to get May in there!
Thanks in advance.
function getNewMonth($x)
{
global $database_fvca, $fvca, $myid, $legacyprint;
mysql_select_db($database_fvca, $fvca);
$sql = "SELECT instid FROM instance WHERE reportyear=".date("Y", $x)." AND reportmonth=".date("n", $x).
" AND orgid=".$myid;
$q = mysql_query($sql);
$n = mysql_num_rows($q);
if ($n == 0)
{
return '<td><a href="monthstart.php?orgid='.$myid.'&month='.date("n", $x).'&year='.
date("Y", $x).'">begin</a></td><td> </td>';
}
else
{
$a = mysql_result($q,0);
return '<td>edit</td><td><a href="viewmonth.php?instid='.$a.
'">view report</a></td>'; } }
function getMonth($date)
{
Hello i'm trying to make a post count function based on the codeigniter framework and what i done so far works great looking by my side. The function is complete and everything works fine.
But i have a question here from some experts to tell me that this is the correct ussage of the function and non of the above will harm my page loading. The function is accesed by jQuery get function on every click on the post.
First i'm checking if there is an ip address and if the ip address date inserted is more then 24 hours if its more i'm deleting the current row and then checking again becuase of the previous select its still remembering the last ip address and inserting again with new datime.
And other question should i make cleanjob every week or similar for all ip addreses ?
Here is my code:
function show_count($post_id){
$ip = $this->input->ip_address();
$this->db->select('ip_address,data');
$this->db->from('post_views');
$this->db->where('ip_address',$ip);
$query = $this->db->get();
foreach ($query->result() as $row){
$ip_address = $row->ip_address;
$data = $row->data;
}
if(isset($ip_address) && time() >= strtotime($data) + 8640){
$this->db->where('ip_address',$ip);
$this->db->delete('post_views');
}
$this->db->select('ip_address');
$this->db->from('post_views');
$this->db->where('ip_address',$ip);
$query = $this->db->get();
foreach ($query->result() as $row){
$ip_address_new = $row->ip_address;
}
if(!isset($ip_address_new) && $ip_address_new == false){
$date = new DateTime('now', new DateTimeZone('Europe/Skopje'));
$this->db->set('views', 'views+ 1', false);
$this->db->where('post_id',$post_id);
$this->db->update('posts');
$data = array(
'ip_address'=>$ip,
'data'=>$date->format("Y-m-d H:i:s")
);
$this->db->insert('post_views',$data);
}
}
Thanks, any suggestions will be appreciate.
Instead of doing lots of queries to increment unique views on your posts, you should use and set cookies and have a fallback method if cookies are not enabled.
$post_id = "???"
if(isset($_COOKIE['read_articles'])) {
//grab the JSON encoded data from the cookie and decode into PHP Array
$read_articles = json_decode($_COOKIE['read_articles'], true);
if(isset($read_articles[$post_id]) AND $read_articles[$post_id] == 1) {
//this post has already been read
} else {
//increment the post view count by 1 using update queries
$read_articles[$post_id] = 1;
//set the cookie again with the new article ID set to 1
setcookie("read_articles",json_encode($read_articles),time()+60*60*24);
}
} else {
//hasn't read an article in 24 hours?
//increment the post view count
$read_articles = Array();
$read_articles[$post_id] = 1;
setcookie("read_articles",json_encode($read_articles),time()+60*60*24);
}
I am facing the problem that when I try to update the amount field in table using query in php code then it is not working. See this image:
But if i did this removing by the financial year field then it is working......
My php code is:
if(isset($_POST['mid_update']))
{
echo $subscription3=$_POST['subscription'];
echo $member_type3=$_POST['member_type'];
echo $financial_year3=$_POST['financial_year'];
echo $amount3=$_POST['amount'];
$qry=mysqli_query($con,"update dbo_tbfeemaster set nu_amount='$amount3' where nu_sub_id='$subscription3' and vc_member_type='$member_type3' and vc_financial_year='$financial_year3'");
if($qry)
{
header("location:subscription_fee_master.php?w=updation success");
}
else
{
header("location:subscription_fee_master.php?w=updation not success");
}
}
With this code the updation is successful showing but table is not updating.
I change date format as:
<option value="<?php $dat1=$q['dt_period_start_date'];
echo date("d-M-Y",strtotime($dat1));?> to <?php $dat2=$q['dt_period_end_date'];
echo date("d-M-Y",strtotime($dat2));?>">
And is equal to the same as database financial year column...
Everthing is going fine then why my table is not updating. Any suggestion would be highly appreciated and feel free to ask me if i forget something to mention here regarding my problem...
It looks like the date formats you use in the query don't line up. Try something like this to make sure the formats are the same. You might want to split those two dates up and store them in separate columns. Which would make this a lot easier imho.
$dateStr = '2011-04-01 to 2012-03-31';
$parts = explode('to', $dateStr);
$result = array_map(function($value) {
$date = date_create(trim($value));
return date_format($date, 'd-M-Y');
}, $parts);
$dateStr = implode(' to ', $result);