i have error with a mysql database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vijaysiva
Forum Newbie
Posts: 1
Joined: Mon Apr 08, 2013 2:55 am

i have error with a mysql database

Post by vijaysiva »

Hi friends,
i m using oscommerce, i have error with date portion. in database i have seen output is 176 with(begin date:2012-12-1 and end date:2012-12-31), but my site out put is 175.



<?php

require ('includes/application_top.php');
//BOF Mod djlounge
require ( DIR_WS_LANGUAGES . $language . '/customer_stats.php');

//EOF Mod djlounge
# Begin class definition
class creport {
var $begindate, $enddate, $globalstartdate, $globalenddate, $mode, $numrecords;
var $values = array();

function creport() {
//this $firstquery used only for get the begining date.
$firstQuery = tep_db_query("select UNIX_TIMESTAMP(min(customers_info_date_account_created)) as first FROM customers_info");
$first = tep_db_fetch_array($firstQuery);
$this->globalstartdate = mktime(date("H", $first['first']), date("i", $first['first']), date("s", $first['first']), date("m", $first['first']), date("d", $first['first']), date("Y", $first['first']));
//echo date("H", $first['first']);
//echo "<br>". date("i", $first['first']);
//echo"<br>". date("s", $first['first']);
$this->begindate = mktime(00, 00,00 , date("m", time()), date("d", "1"), date("Y", time()));
$this->globalenddate = mktime(date("H", time()),date("i", time()), date("s", time()), date("m", time()), date("d", time()), date("Y", time()));
// echo date("H", time());
//echo date("i", time());
//echo date("s", time());
$this->enddate = $this->globalenddate;
// $this->enddateclean = date("F j, Y", $this->enddate);

//totally how many customers?this part is connected to the line 118
$timeframequery = "SELECT * FROM `customers_info`";
$timeframearray = tep_db_query($timeframequery);
$this->numrecords = tep_db_num_rows($timeframearray);
}

function getnext() {

//begin date smaller than globalstartdate , below if condition is worked , other wise go to the next line..
if ($this->begindate < $this->globalstartdate) {
$this->begindate = $this->globalstartdate;
}


switch ($this->mode) {
// yearly
case '1':
$sd = $this->begindate; //mktime(0, 0, 0,$month , $day, $year);
$ed = mktime(00, 00, 00, date("m", $sd), date("d", $sd), date("Y", $sd) + 1);
break;
// monthly
case '2':
$sd = $this->begindate; //mktime(0, 0, 0,$month , $day, $year);
$ed = mktime(00, 00, 00, date("m", $sd) + 1, 1, date("Y", $sd));
break;
// weekly
case '3':
$sd = $this->begindate; //mktime(0, 0, 0,$month , $day, $year);
$ed = mktime(00,00, 00, date("m", $sd), date("d", $sd) + 7, date("Y", $sd));
break;
// daily
case '4':
$sd = $this->begindate; //mktime(0, 0, 0,$month , $day, $year);
$ed = mktime(00, 00, 00, date("m", $sd), date("d", $sd) + 1, date("Y", $sd));
break;
default:
$sd = $this->begindate; //mktime(0, 0, 0,$month , $day, $year);
$ed = mktime(00, 00, 00, date("m", $sd), date("d", $sd) + 7, date("Y", $sd));
break;
}//end switch

// $this->enddate = mktime(23, 59, 59, date("m", $sd), 31, date("Y", $sd));
// echo $this->begindate . "<br>";
// echo date("Y-m-d H:i:s",$this->begindate). "<br>";
// echo $this->enddate . "<br>";
// echo date("Y-m-d H:i:s",$this->enddate). "<br>";

if ($this->enddate > $this->globalenddate)
$this->enddate = $this->globalenddate;
//probelm is here
if ($ed > $this->enddate)
$ed = $this->enddate;


//start date is denoted by $sd, and end date is specified by $ed.
$timeframequery = "SELECT * FROM `customers_info` WHERE UNIX_TIMESTAMP(`customers_info_date_account_created`) >= '" . $sd . "' AND UNIX_TIMESTAMP(`customers_info_date_account_created`) <= '" . $ed . "'";
echo "SELECT * FROM `customers_info` WHERE UNIX_TIMESTAMP(`customers_info_date_account_created`) >= '" . $sd . "' AND UNIX_TIMESTAMP(`customers_info_date_account_created`)<= '" . $ed . "'<br>";
//begin date vanthu end date la eirunthu arampikum
$this->begindate = $ed;

$timeframearray = tep_db_query($timeframequery);
$this->numrecords = tep_db_num_rows($timeframearray);
$this->values[] = $this->numrecords;
echo '<tr>
<td width="125px" align="left" >' . date("D M j, y,H:i:s", $sd) . '</td>
<td width="125px" align="left" >' . date("D M j, y,H:i:s", $ed) . '</td>
<td><b>' . $this->numrecords . '</b></td>
</tr>';
}

# end getnext
}

# end creport class
# Create a new instance of the creport class
$report = new creport;

if ($_POST['mode']) {
$mode = $_POST['mode'];
}
if ($mode < 1 || $mode > 4) {
$mode = 2;
}

if($_POST){
//post method
$startdate = $_POST['startdate'];
$enddate = $_POST['enddate'];

//split date part
list($month,$day, $year) = split('[/.-]', $startdate);
list($month_1, $day_1, $year_1) = split('[/.-]', $enddate);

//echo $year;
$report->begindate = mktime(00, 00, 00, $month, $day, $year);
$report->enddate = mktime(23, 59, 59, $month_1, $day_1, $year_1);
}
// print_r($_POST);
$report->mode = $mode;
require(DIR_WS_INCLUDES . 'header.php');
?>

<table width="80%" cellspacing="2" cellpadding="1">
<tr>
<td valign="top" align="left">
<p><?php echo HEADING_TITLE;?></p>
<p><?php echo TEXT_DATAFROM;?><b><?php echo date("D M j, Y", $report->begindate); ?></b><?php echo TEXT_TO;?><b><?php echo date("D M j, Y", $report->enddate); ?></b></p>
<p><?php echo TEXT_TOTAL_ACCOUNTS;?><b><?php echo $report->numrecords; ?></b></p>
<form name="options" method="post" class="form-inline">
<table width="100%" class="table table-bordered" >
<tr>
<td valign="top" width="125px">

<input name="mode" type="radio" value="1" <? if ($mode == 1) echo "checked"; ?> ><?php echo TEXT_YEARLY;?><br>
<input name="mode" type="radio" value="2"<? if ($mode == 2) echo "checked"; ?> ><?php echo TEXT_MONTHLY;?><br>
<input name="mode" type="radio" value="3"<? if ($mode == 3) echo "checked"; ?> ><?php echo TEXT_WEEKLY;?><br>
<input name="mode" type="radio" value="4"<? if ($mode == 4) echo "checked"; ?> ><?php echo TEXT_DAILY;?><br>
</td>
<td valign="top">
<table width="100%" >
<tr>
<td width="100%" style="padding: 10px">
<?php require(DIR_WS_MODULES . 'calendar_control.php');?>
<input type="submit" name="Submit" class="btn btn-primary" value="<? echo TEXT_SUBMIT ?>">

</td>
</tr>
</table>
</td>
</tr></table>
</form>
<br>
<table width="60%" class="table table-bordered" >
<tr>
<td width="20%" align="left"><b><?php echo TEXT_BEGINDATE;?></b></td>
<td width="20%" align="left"><b><?php echo TEXT_ENDDATE;?></b></td>
<td align="left"><b><?php echo TEXT_NUMBER_OF_ACCOUNTS_CREATED;?></b></td>
</tr>
<?php
while ($report->begindate < $report->enddate) {
$report->getnext();
}
?>

</table>
</td></tr></table>
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php');?>

i have tried one more weeks but i dont get any correct output
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: i have error with a mysql database

Post by Jade »

Have you checked to make sure the database has the correct date it in? Have you tried just echo-ing the values in the database? Have you tried formatting the date in your query using date_format? I would suggest that if you want to format the dates in php you do the following:

Code: Select all

//this $firstquery used only for get the begining date.
$firstQuery = tep_db_query("select min(customers_info_date_account_created) as first FROM customers_info");
$first = tep_db_fetch_array($firstQuery);
$this->globalstartdate = date("n-j-Y", strtotime($first['first']));
Post Reply