Jump to content

Recommended Posts

Since we upgraded it seems I've lost some reporting functionality... I'm not sure if it's PHP or a bad MySQL statement but everything pulls data except this line:

 

$todays_reservations = $reservations[$day][$reservationist["username"]]

 

 

Is my syntax incorrect to the new standard? It should be looking up how many days a reservationist has booked for each day. This all worked fine on a PHP4/MySQL 3.2.3 setup.

 

EX.:

Day      1  2  3  4

Jeff      5  2  5  8

 

$SQLreservationist = "Select username from admin_users";
$qreservationist = mysql_query($SQLreservationist);

//pre-process the list to skip anybody who didn't have any reservations this month
foreach($reservations as $subarray) 
{
foreach($subarray as $user_name => $res_count)
{
	$reservationist_total[$user_name] += $res_count;
}
}

while($reservationist = mysql_fetch_array($qreservationist)) {
if($reservationist_total[$reservationist["username"]] == 0) {
	continue;
}
$MTDreservations = 0;

?>

<td><?=$reservationist["username"] ?> </td>

<?
for($i="01"; $i <= $lastday; $i++) {
	$day = sprintf("%04d%02d%02d", $year, $month, $i);
    $todays_reservations = $reservations[$day][$reservationist["username"]];
    $MTDreservations += $todays_reservations;
    $daily["$day"] += $todays_reservations;

  ?>
  	<td align=right><?=$todays_reservations ?></td>

Link to comment
https://forums.phpfreaks.com/topic/242610-upgraded-from-php4-to-5-syntax-error/
Share on other sites

Mainly just notices. I just tried to run this against my old SQL 3.23 and it worked. Maybe my query statements are now outdated a little bit?

 

Notice: Use of undefined constant d - assumed 'd' in /home/cfv/public_html/admin/resvprod.php on line 6

Notice: Use of undefined constant m - assumed 'm' in /home/cfv/public_html/admin/resvprod.php on line 8

Notice: Use of undefined constant Y - assumed 'Y' in /home/cfv/public_html/admin/resvprod.php on line 10

Notice: Undefined variable: SQLnewreservation in /home/cfv/public_html/admin/resvprod.php on line 76

Notice: Undefined variable: reservations in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: 2011-07- in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: Online Reservation in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: scott in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: lindsey in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: shaun in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: jamie in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: james in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: debbie in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: kenny in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: lee in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: courtney in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: amanda in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: Melena in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: Alan in /home/cfv/public_html/admin/resvprod.php on line 81

Notice: Undefined index: Online Reservation in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: scott in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: lindsey in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: shaun in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: jamie in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: james in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: debbie in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: kenny in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: lee in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: courtney in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: amanda in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: Melena in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: Alan in /home/cfv/public_html/admin/resvprod.php on line 92

Notice: Undefined index: 20110701 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110702 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110703 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110704 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110705 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110706 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110707 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110708 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110709 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110710 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110711 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110712 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110713 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110714 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110715 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110716 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110717 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110718 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110719 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110720 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110721 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110722 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110723 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110724 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110725 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110726 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110727 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110728 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110729 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110730 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined index: 20110731 in /home/cfv/public_html/admin/resvprod.php on line 116

Notice: Undefined variable: MTD_total in /home/cfv/public_html/admin/resvprod.php on line 127

Notice: Undefined variable: Rev_total in /home/cfv/public_html/admin/resvprod.php on line 128

Notice: Undefined variable: Pot_total in /home/cfv/public_html/admin/resvprod.php on line 129

 

 

Full code:

<? error_reporting(E_ALL); ?>


<? 
include("header.php");
$day = date(d);
if(!isset($month))
$month= date(m);
if(!isset($year))
$year=date(Y);
$firstday = "01";
//$firstday="18";
$lastday = 31;
while(!checkdate($month,$lastday,$year)) {
$lastday--;
}

$timestart =mktime(0, 0, 0, $month, $firstday, $year); 
$timeend = mktime(23, 59, 59, $month, $lastday, $year);
?>
<h1> Reservations Productivity Report </h1>

<form method="get" action="resvprod.php">
<select name=month>
  <?  for($i = 1; $i <= 12; $i++) { ?>
<option value="<?=$i?>" <?=($i==$month)?"SELECTED":""?>><?=strftime("%B", mktime(0,0,0,$i,1,2004));?></option>
  <? } ?>
</select>

<select name=year>
  <? for($i = 2001; $i <= date(Y); $i++) { ?>
<option value="<?=$i?>" <?=($i==$year)?"SELECTED":""?>><?=$i?></option>
<? } ?>
</select>

<input type=submit value="Go">
</form>
<table border=0>
<tr>
<td><b>Reservationist </b></td>

<? for($i=1; $i <= $lastday; $i++) { ?>
<td style="width:12px; font-weight: bold;" align=right><?=$i ?> </td>
<? } ?>


<td><b>MTD </b></td>
<td><b>Potential Revenue </b></td>
<td><b>Actual Revenue </b></td> 
<td><b>Percentage</b></td>
</tr>
<tr>
<? 
$tstamp_start = strftime("%Y%m%d000000", $timestart);
$tstamp_end = strftime("%Y%m%d235959", $timeend);
$SQLdiscount = "Select username, sum(value) as discount from reservation, res_log, adjustments, admin_users where res_log.reservationist_id=admin_users.id and reservation.id=res_log.reservation_id and reservation.id=adjustments.reservation_id and res_log.type='1' and reservation.type='Guest' and res_log.timestamp >='$tstamp_start' and res_log.timestamp <='$tstamp_end' GROUP BY res_log.reservationist_id";

$qdiscount= mysql_query($SQLdiscount);
while($discount = mysql_fetch_array($qdiscount))
{
   $adjustment[$discount["username"]] = $discount["discount"];
}


$SQLamount = "Select username, sum(rate) as rate from reservation, res_log, reservation_rates, admin_users where res_log.reservationist_id=admin_users.id and reservation.id=res_log.reservation_id and reservation.id=reservation_rates.reservation_id and res_log.type='1' and reservation.type='Guest' and res_log.timestamp >='$tstamp_start' and res_log.timestamp <='$tstamp_end' GROUP BY res_log.reservationist_id";

$qamount = mysql_query($SQLamount);

while($amount = mysql_fetch_array($qamount))
{
    $rate[$amount["username"]] = $amount["rate"];
}

$SQLnumreserv = "Select username, COUNT(res_log.reservation_id) as numresv, LEFT(res_log.timestamp, as tstamp from res_log, admin_users, reservation where reservation.id=reservation_id and reservationist_id=admin_users.id and res_log.timestamp >='$tstamp_start' and res_log.timestamp<='$tstamp_end' and res_log.type='1' and reservation.type='Guest' GROUP BY LEFT(res_log.timestamp,, username ORDER BY res_log.reservationist_id";

$newreservation= mysql_query($SQLnewreservation);
$numresrv= mysql_query($SQLnumreserv);


while($reserv = mysql_fetch_array($numresrv)){
  $reservations[$reserv["tstamp"]][$reserv["username"]] += $reserv["numresv"];
}

$SQLreservationist = "Select username from admin_users";
$qreservationist = mysql_query($SQLreservationist);

//pre-process the list to skip anybody who didn't have any reservations this month
foreach($reservations as $subarray) 
{
foreach($subarray as $user_name => $res_count)
{
	$reservationist_total[$user_name] += $res_count;
}
}

$colors = Array("#CCCCCC", "#EEEEEE");
$j =0;

while($reservationist = mysql_fetch_array($qreservationist)) {
if((isset($reservationist_total[$reservationist["username"]])) == 0) {
	continue;
}
$MTDreservations = 0;
$j %= count($colors);
?>
<tr  style="background-color:<?=$colors[$j]?>; border-left:1px solid black">
<? $j++; ?>

<td><?=$reservationist["username"] ?> </td>

<?
for($i="01"; $i <= $lastday; $i++) {
	$day = sprintf("%04d%02d%02d", $year, $month, $i);
    $todays_reservations = (isset($reservations[$day][$reservationist["username"]]));
    $MTDreservations += $todays_reservations;
    $daily["$day"] += $todays_reservations;

  ?>
  	<td align=right><?=$todays_reservations ?></td>
  <? }

	$user = $reservationist["username"];
  $Revenue = $rate[$user];
$Potrev = $rate[$user] + $adjustment[$user];
$Percentage = ($Revenue > 0) ? ($Potrev/$Revenue) : 0;

$MTD_total += $MTDreservations;
$Rev_total += $Revenue;
$Pot_total += $Potrev;
?>

<td align=right><?= ($MTDreservations) ? $MTDreservations : "-" ?> </td>                               
<td align=right><?= ($Revenue) ? number_format($Revenue, 2) : "-" ?> </td>
<td align=right><?= ($Potrev) ? number_format($Potrev,2) : "-" ?> </td>
<td align=right><?= ($Percentage) ? sprintf("%.2f%%", $Percentage * 100.0) : "-"?> </td>
</tr>
<? } ?>
<tr> 
<td><b>Daily Total </b></td>
<? for($i="01"; $i <= $lastday; $i++) { 
	$day = sprintf("%04d%02d%02d", $year, $month, $i);
?>
<td><b><?=isset($daily["$day"]) ?></b></td>
<?  }  ?>
  <td><b><?= $MTD_total ?></b></td>
<td align=right><b><?= ($Rev_total) ? number_format($Rev_total, 2) : "-"  ?></b></td>
<td align=right><b><?= ($Pot_total) ? number_format($Pot_total, 2) : "-" ?></b> </td>
<td align=right><b><?= ($Rev_total) ? sprintf("%.2f%%", ($Pot_total/$Rev_total)*100.0) : "-"?></td>
</tr>
</table>

Did your mysql get upgraded too? You didn't exactly state so.

 

It's more likely that you either don't have any matching data (or no data at all) in your database or that the conditions being produced by php (the strftime() statements) going into the query statements are not what you think.

 

Have you echoed out the sql query statement(s) to see what they actually are and used print_r or var_dump on the data to check if it is what you expect?

I dumped the DB from 3.23 and imported into 5.0.  Out of over 100 pages, this is the only one that has a major issue. I can see the correct reservationists being pulled and printed and even their earnings.... total reservations listed by each day, however, do not work. Any recommendations on which query or variable to print_r on?

 

<?=$todays_reservations ?>  - This doesn't produce anything, but the others work fine  :-\

var_dump($reservations); =

 

array(1) {
  ["2011-07-"]=>
  array(13) {
    ["Online Reservation"]=>
    int(194)
    ["scott"]=>
    int(1)
    ["lindsey"]=>
    int(33)
    ["shaun"]=>
    int(1)
    ["jamie"]=>
    int(11)
    ["james"]=>
    int(32)
    ["debbie"]=>
    int(44)
    ["kenny"]=>
    int(24)
    ["lee"]=>
    int(34)
    ["courtney"]=>
    int(11)
    ["amanda"]=>
    int(32)
    ["Melena"]=>
    int(31)
    ["Alan"]=>
    int(24)
  }
}

Seriously, did you look at YOUR data that was displayed to see what was wrong with it?

 

The date index is only "2011-07-". How is that going to match the $day variable which would have values like "2011-07-01".

 

The LEFT(res_log.timestamp,8) as tstamp term in your query is only giving "2011-07-".

 

Since I don't know if/how/or what mysql 3 returned for a DATE/DATETIME/TIMESTAMP data type, you would need to change any usage of LEFT(...,8) to LEFT(...,10) or you can just use the mysql DATE() function to get the date part of a DATETIME/TIMESTAMP data type.

'$day' - prints out "string(8) "20110731""

 

$reservations - prints out a good looking:

 

array(22) {
  ["2011-07-06"]=>
  array(7) {
    ["Online Reservation"]=>
    int(10)
    ["lindsey"]=>
    int(1)
    ["jamie"]=>
    int(1)
    ["james"]=>
    int(1)
    ["debbie"]=>
    int(2)
    ["kenny"]=>
    int(2)
    ["amanda"]=>
    int(4)
  }
  ["2011-07-22"]=>
  array(5) {
    ["Online Reservation"]=>
    int(2)
    ["jamie"]=>
    int(2)
    ["debbie"]=>
    int(2)
    ["lee"]=>
    int(1)
    ["Melena"]=>
    int(2)
  }
  ["2011-07-01"]=>
  array(9) {
    ["Online Reservation"]=>
    int(10)
    ["lindsey"]=>
    int(1)
    ["james"]=>
    int(4)
    ["debbie"]=>
    int(4)
    ["kenny"]=>
    int(1)
    ["courtney"]=>
    int(1)
    ["amanda"]=>
    int(3)
    ["Melena"]=>
    int(2)
    ["Alan"]=>
    int(2)
  }
  ["2011-07-17"]=>
  array(4) {
    ["Online Reservation"]=>
    int(14)
    ["james"]=>
    int(1)
    ["Melena"]=>
    int(3)
    ["Alan"]=>
    int(2)
  }
  ["2011-07-12"]=>
  array(7) {
    ["Online Reservation"]=>
    int(
    ["lindsey"]=>
    int(5)
    ["kenny"]=>
    int(2)
    ["lee"]=>
    int(3)
    ["amanda"]=>
    int(3)
    ["Melena"]=>
    int(2)
    ["Alan"]=>
    int(1)
  }
  ["2011-07-07"]=>
  array(6) {
    ["Online Reservation"]=>
    int(11)
    ["lindsey"]=>
    int(2)
    ["jamie"]=>
    int(1)
    ["james"]=>
    int(6)
    ["debbie"]=>
    int(3)
    ["courtney"]=>
    int(3)
  }
  ["2011-07-02"]=>
  array(5) {
    ["Online Reservation"]=>
    int(
    ["james"]=>
    int(3)
    ["lee"]=>
    int(3)
    ["courtney"]=>
    int(2)
    ["Alan"]=>
    int(2)
  }
  ["2011-07-18"]=>
  array(7) {
    ["Online Reservation"]=>
    int(
    ["james"]=>
    int(1)
    ["debbie"]=>
    int(3)
    ["lee"]=>
    int(3)
    ["courtney"]=>
    int(1)
    ["amanda"]=>
    int(2)
    ["Alan"]=>
    int(3)
  }
  ["2011-07-13"]=>
  array(7) {
    ["Online Reservation"]=>
    int(10)
    ["lindsey"]=>
    int(2)
    ["james"]=>
    int(1)
    ["debbie"]=>
    int(5)
    ["lee"]=>
    int(2)
    ["courtney"]=>
    int(1)
    ["Melena"]=>
    int(4)
  }
  ["2011-07-08"]=>
  array(5) {
    ["Online Reservation"]=>
    int(10)
    ["lindsey"]=>
    int(3)
    ["debbie"]=>
    int(1)
    ["kenny"]=>
    int(5)
    ["Melena"]=>
    int(
  }
  ["2011-07-03"]=>
  array(2) {
    ["Online Reservation"]=>
    int(4)
    ["amanda"]=>
    int(1)
  }
  ["2011-07-19"]=>
  array( {
    ["Online Reservation"]=>
    int(9)
    ["lindsey"]=>
    int(2)
    ["jamie"]=>
    int(2)
    ["james"]=>
    int(2)
    ["debbie"]=>
    int(2)
    ["kenny"]=>
    int(2)
    ["lee"]=>
    int(4)
    ["Melena"]=>
    int(1)
  }
  ["2011-07-14"]=>
  array(7) {
    ["Online Reservation"]=>
    int(10)
    ["lindsey"]=>
    int(1)
    ["shaun"]=>
    int(1)
    ["james"]=>
    int(2)
    ["debbie"]=>
    int(4)
    ["lee"]=>
    int(3)
    ["Alan"]=>
    int(1)
  }
  ["2011-07-09"]=>
  array(5) {
    ["Online Reservation"]=>
    int(11)
    ["james"]=>
    int(5)
    ["lee"]=>
    int(5)
    ["amanda"]=>
    int(4)
    ["Alan"]=>
    int(1)
  }
  ["2011-07-04"]=>
  array(7) {
    ["Online Reservation"]=>
    int(
    ["debbie"]=>
    int(4)
    ["kenny"]=>
    int(2)
    ["courtney"]=>
    int(1)
    ["amanda"]=>
    int(2)
    ["Melena"]=>
    int(2)
    ["Alan"]=>
    int(1)
  }
  ["2011-07-20"]=>
  array(9) {
    ["Online Reservation"]=>
    int(3)
    ["scott"]=>
    int(1)
    ["lindsey"]=>
    int(2)
    ["jamie"]=>
    int(1)
    ["james"]=>
    int(2)
    ["debbie"]=>
    int(1)
    ["kenny"]=>
    int(4)
    ["amanda"]=>
    int(1)
    ["Melena"]=>
    int(1)
  }
  ["2011-07-15"]=>
  array(6) {
    ["Online Reservation"]=>
    int(
    ["debbie"]=>
    int(5)
    ["lee"]=>
    int(4)
    ["courtney"]=>
    int(2)
    ["amanda"]=>
    int(3)
    ["Alan"]=>
    int(2)
  }
  ["2011-07-10"]=>
  array(5) {
    ["Online Reservation"]=>
    int(13)
    ["james"]=>
    int(4)
    ["lee"]=>
    int(1)
    ["Melena"]=>
    int(3)
    ["Alan"]=>
    int(1)
  }
  ["2011-07-05"]=>
  array(5) {
    ["Online Reservation"]=>
    int(
    ["lindsey"]=>
    int(1)
    ["jamie"]=>
    int(1)
    ["debbie"]=>
    int(1)
    ["amanda"]=>
    int(4)
  }
  ["2011-07-21"]=>
  array(7) {
    ["Online Reservation"]=>
    int(
    ["lindsey"]=>
    int(5)
    ["jamie"]=>
    int(3)
    ["debbie"]=>
    int(4)
    ["kenny"]=>
    int(3)
    ["lee"]=>
    int(5)
    ["Alan"]=>
    int(2)
  }
  ["2011-07-16"]=>
  array(5) {
    ["Online Reservation"]=>
    int(14)
    ["lindsey"]=>
    int(2)
    ["amanda"]=>
    int(3)
    ["Melena"]=>
    int(3)
    ["Alan"]=>
    int(4)
  }
  ["2011-07-11"]=>
  array(6) {
    ["Online Reservation"]=>
    int(7)
    ["lindsey"]=>
    int(6)
    ["debbie"]=>
    int(3)
    ["kenny"]=>
    int(3)
    ["amanda"]=>
    int(2)
    ["Alan"]=>
    int(2)
  }
}

 

But I print: $todays_reservations, I get a bool(false)...

Forgot to mention, I changed the LEFT(...,8) to LEFT(...,10). Looks like it's getting somewhere!

 

I also modified the sprint to:

sprintf("%04d-%02d-%02d", $year, $month, $i);

 

Still stumped as to why this is returning bool(false):

$todays_reservations = $reservations[$day][$reservationist["username"]]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.