Why won't my page refresh? - php

I have a small time slot booking system, where I can click a link called: Reserve, and then I reserve that given time.
However, the page doesn't refresh after I've clicked on reserve. Therefore it's possible for a user to click the same reserve link twice. Whitch they shouldn't be able to.
if (isset ( $_GET ['reserved'] )) {
$sqlreserve = "INSERT INTO calendar (eventDate, timeslot) VALUES ('" . $dateToCompare . "','" . intval($_GET['t']) . "');";
$resultreserve = mysqli_query ( $mysqli1, $sqlreserve );
if ($resultreserve) {
header('Location: '.$_SERVER['PHP_SELF']);
} else {
echo "Event Failed to add";
}
}
If my insert works, then I call: header('Location: '.$_SERVER['PHP_SELF']);
I'm working on localhost, if that has anything to say?
EDIT:
The way I create my links and the text saying that a slot is booked is like this:
if (mysqli_num_rows ( $result ) == 0) {
echo "<a href='" . $_SERVER ['PHP_SELF'] . "?month=" . $month . "&day=" . $day . "&year=" . $year . "&t={$time}&v=true&f=true&reserved=true'><h3 style='color: rgb(255,0,0);'>Reserve</h3></a>";
} else {
echo "<h3>Not Available, taken by:</h3>";
while ( $row = mysqli_fetch_array ( $result ) ) {
echo "<br />";
}
}
EDIT. My Error:
Cannot modify header information - headers already sent by (output started.....)
for($i = 1; $i < $numDays; $i ++, $counter ++) {
$timeStamp = strtotime ( "$year-$month-$i" );
if ($i == 1) {
$firstDay = date ( "w", $timeStamp );
for($j = 0; $j < $firstDay; $j ++, $counter ++) {
echo "<td> </td>";
}
}
if ($counter % 7 == 0) {
echo "</tr><tr>";
}
$monthstring = $month;
$monthlength = strlen ( $monthstring );
$daystring = $i;
$daylength = strlen ( $daystring );
if ($monthlength <= 1) {
$monthstring = "0" . $monthstring;
}
if ($daylength <= 1) {
$daystring = "0" . $daystring;
}
$todaysDate = date ( "m/d/Y" );
$dateToCompare = $monthstring . '/' . $daystring . '/' . $year;
echo "<td align='center' ";
if ($todaysDate == $dateToCompare) {
echo "class='today'";
} else {
$sqlCount = "SELECT * FROM calendar WHERE eventDate='" . $dateToCompare . "'";
$noOfEvent = mysqli_num_rows ( mysqli_query ( $mysqli1, $sqlCount ) );
if ($noOfEvent >= 1) {
echo "class='event'";
}
}
echo "><a href='" . $_SERVER ['PHP_SELF'] . "?month=" . $monthstring . "&day=" . $daystring . "&year=" . $year . "&v=true'>" . $i . "</a></td>";
}
The line affected is:
echo "><a href='" . $_SERVER ['PHP_SELF'] . "?month=" . $monthstring . "&day=" . $daystring . "&year=" . $year . "&v=true'>" . $i . "</a></td>";
It is in another file where I have my calendar, in which I have links to the specific day that I wan't to book the timeslots fore:

Try this..
header('Location: '.$_SERVER['PHP_SELF']);
exit;
I think your code is continuing...
A more in-depth explanation can be found here: Why I have to call 'exit' after redirection through header('Location..') in PHP?
EDIT
It's clear now that Milen Georgiev answer is correct. You output content to the browser before you reach the header(); You need to move the if statement in the top part of your PHP code to avoid the header content error.
if (isset ( $_GET ['reserved'] )) {
$sqlreserve = "INSERT INTO calendar (eventDate, timeslot) VALUES ('" . $dateToCompare . "','" . intval($_GET['t']) . "');";
$resultreserve = mysqli_query ( $mysqli1, $sqlreserve );
if ($resultreserve) {
header('Location: '.$_SERVER['PHP_SELF']);
exit;
} else {
echo "Event Failed to add";
}
}

Do you send(output/echo) anything before header('Location: '.$_SERVER['PHP_SELF']); ?
If that is the case, you will have to turn the object buffer on. Using header, you always have to send the headers first or it will not work.

Related

Different Variables with same value effecting change on the other

Question:
Is there something weird about date-time that would affect the assignment of a variable?
The situation:
From Controller I'm passing a variable $startDate and on the view assigning it to different variables $day1, $day2, etc etc. I go through a loop on $day1 and I modify the day to increment $day1 by 1 using $day1->modify("+1 day")
$day2 the loop (in the else portion) doesn't trigger because the value of $startDate is too high. however, it's value should be the same as $day1 before modification.
the Code:
The controller
public function appointmentSearch()
{
$counselor = $this->session->userdata('idUser');
if($this->input->post('SearchAppointments'))
{
$fromDate = $_POST['fromDate'];
$fromTimeSlot = $this->Admin_model->TimeConversion($_POST['fromTime']);
$toDate = $_POST['toDate'];
$toTimeSlot = $this->Admin_model->TimeConversion($_POST['toTime']);
$theStart = new DateTime($fromDate);
$theEnd = new DateTime($toDate);
$difference = $theEnd->diff($theStart);
$dayCount = $difference->d;
$timeCount = (int)$toTimeSlot-(int)$fromTimeSlot;
$data['schedule'] = true;
$data['days'] = $dayCount;
$data['slots'] = $timeCount;
$data['dayStart'] = $theStart;
$data['dayEnd'] = $theEnd;
$data['slotStart'] = $fromTimeSlot;
$data['slotEnd'] = $toTimeSlot;
$data['r1Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,1);
$data['r2Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,2);
$data['r3Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,3);
$data['r4Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,4);
$data['r5Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,5);
$data['r6Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,6);
$data['r7Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,7);
$data['r8Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,8);
$data['r9Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,9);
$data['r10Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,10);
$this->load->view('admin/scheduler',$data);
}
}
The View:
<?php
if($schedule == true)
{ //if false we have search results
//classes for the form
$attributes = array('class' => 'row');
//normal attributtes for the time slots if they are blacked out
$subAttUnav = array('class' => 'btn btn-secondary btn-sm');
// if the used time slot is someone they can ask to move
$subAttMove = array('class' => 'btn btn-secondary btn-sm', 'style' => 'background:darkgrey;');
// it's wide open
$subAttOpen = array('class' => 'btn btn-secondary btn-sm');
if(count($r1Data) >= 1)
{ //room 1 has appoints scheduled during the time frame queried
echo '<div class="row" style="width:70%;margin:0 auto;"><h3 class="highlight">Room 1</h3>';
$day1 = $dayStart;
while($day1 <= $dayEnd)
{
$day1format = $day1->format('Y-m-d-H-i-s');
$dayArray = explode('-',$day1format);
for($i = 0;$i <= $slots; $i++)
{
$timeslot = $slotStart + $i;
$label = 'Book: ' . $timeslot . ':00 on ' . $dayArray[1] . '/' . $dayArray[2] . ' ';
foreach($r1Data as $index)
{
$row = explode('-',$index);
//var_dump($row);
$thisDay = $dayArray[0] . '/' . $dayArray[1] . '/' . $dayArray[2];
//echo '$thisDay =' . $thisDay . '</br>';
$apptDay = $row[6] . '/' . $row[7] . '/' . $row[8];
//echo '$apptDay =' . $apptDay . '</br>';
//echo '$timeslot =' . $timeslot . '</br>';
//echo '$row[9] =' . $row[9] . '</br>';
if($thisDay == $apptDay && $timeslot == (int)$row[9])
{ // the appointment date and timeslot matches current slide
echo '<div class="btn btn-secondary btn-sm m-1" style="background:black;" title="Time unavailable">' . $label . '</div>';
}
else
{
echo form_open('AdminForms/booking/' . $dayArray[0] . '/' . $dayArray[1] . '/' . $dayArray[2] . '/' . $timeslot . '/1', $attributes);
echo form_submit("Book",$label,$subAttOpen);
echo form_close();
}
}
}
$placeholder = $day1->modify('+1 day');
$day1 = $placeholder;
}
echo '</div><!-- End of Room 1 data -->';
}
else
{ // no results on query the time frame is wide open
echo '<div class="row" style="width:70%;margin:0 auto;"><h3 class="highlight">Room 1</h3>';
$day1 = $dayStart;
while($day1 <= $dayEnd)
{
$day1format = $day1->format('Y-m-d-H-i-s');
$dayArray = explode('-',$day1format);
for($i = 0;$i <= $slots; $i++)
{
$timeslot = $slotStart + $i;
$label = 'Book: ' . $timeslot . ':00 on ' . $dayArray[1] . '/' . $dayArray[2] . ' ';
echo form_open('AdminForms/booking/' . $dayArray[0] . '/' . $dayArray[1] . '/' . $dayArray[2] . '/' . $timeslot . '/1', $attributes);
echo form_submit("Book",$label,$subAttOpen);
echo form_close();
}
$placeholder = $day1->modify('+1 day');
$day1 = $placeholder;
}
echo '</div><!-- End of Room 1 data -->';
var_dump($dayStart);
}
if(count($r2Data) >= 1)
{ //room 1 has appoints scheduled during the time frame queried
echo '<div class="row" style="width:70%;margin:0 auto;"><h3 class="highlight">Room 2</h3>';
$day2 = $dayStart;
while($day2 <= $dayEnd)
{
$day2format = $day2->format('Y-m-d-H-i-s');
$day2Array = explode('-',$day2format);
for($i = 0;$i <= $slots; $i++)
{
$timeslot = $slotStart + $i;
$label = 'Book: ' . $timeslot . ':00 on ' . $day2Array[1] . '/' . $day2Array[2] . ' ';
foreach($r2Data as $index)
{
$row = explode('-',$index);
//var_dump($row);
$thisDay = $day2Array[0] . '/' . $day2Array[1] . '/' . $day2Array[2];
//echo '$thisDay =' . $thisDay . '</br>';
$apptDay = $row[6] . '/' . $row[7] . '/' . $row[8];
//echo '$apptDay =' . $apptDay . '</br>';
//echo '$timeslot =' . $timeslot . '</br>';
//echo '$row[9] =' . $row[9] . '</br>';
if($thisDay == $apptDay && $timeslot == (int)$row[9])
{ // the appointment date and timeslot matches current slide
echo '<div class="btn btn-secondary btn-sm m-1" style="background:black;" title="Time unavailable">' . $label . '</div>';
}
else
{
echo form_open('AdminForms/booking/' . $day2Array[0] . '/' . $day2Array[1] . '/' . $day2Array[2] . '/' . $timeslot . '/1', $attributes);
echo form_submit("Book",$label,$subAttOpen);
echo form_close();
}
}
}
$placeholder2 = $day2->modify('+1 day');
$day2 = $placeholder2;
}
echo '</div<!-- End of Room 2 data -->';
}
else
{ // no results on query the time frame is wide open
echo '<div class="row" style="width:70%;margin:0 auto;"><h3 class="highlight">Room 2</h3>';
$day2 = $startDate;
while($day2 <= $dayEnd)
{
$day2format = $day2->format('Y-m-d-H-i-s');
$day2Array = explode('-',$day2format);
for($i = 0;$i <= $slots; $i++)
{
$timeslot = $slotStart + $i;
$label = 'Book: ' . $timeslot . ':00 on ' . $day2Array[1] . '/' . $day2Array[2] . ' ';
echo form_open('AdminForms/booking/' . $day2Array[0] . '/' . $day2Array[1] . '/' . $day2Array[2] . '/' . $timeslot . '/1', $attributes);
echo form_submit("Book",$label,$subAttOpen);
echo form_close();
}
$placeholder2 = $day2->modify('+1 day');
$day2 = $placeholder2;
}
echo '</div><!-- End of Room 2 data -->';
}

php Switch/case doesn't work

I tried to find my answer in the other switch/case question. But i don't find the solution.
I got a switch that split my date values in 4 different quarters.
But when i want to print it out, it doesn't work. I don't know what i'm doing wrong.
is this a typo or?
Thanks in advance.
MY CODE
while (odbc_fetch_row($result)) { // while there are rows
$overweight = odbc_result($result, "Weight1") - 44000;
//$total_overweight += $overweight;
$date = date("Y-m-d", strtotime(odbc_result($result, "Date1")));
$companies[] = odbc_result($result, "String3");
$weight = odbc_result($result, "Weight1");
$item['nrplaat'] = odbc_result($result, "String1");
$item['tptcode'] = odbc_result($result, "String3");
$item['chrononr'] = odbc_result($result, "String15");
$item['projectcode'] = odbc_result($result, "String4");
$item['projectnaam'] = odbc_result($result, "String8");
$item['1eweging'] = $weight;
$item['overweighted'] = $overweight;
$item['date'] = $date;
$item['2eweging'] = odbc_result($result, "Weight2");
$item['netto'] = odbc_result($result, "Nett");
switch($weight){
case($weight > '44000' && $weight <= '44500'):
$item['class'] = 'lichtgroen';
case($weight > '44500' && $weight <= '45000'):
$item['class'] = 'groen';
case($weight > '45000' && $weight <= '46000'):
$item['class'] = 'donkergroen';
case($weight > '46000' && $weight <= '47000'):
$item['class'] = 'bruingroen';
case($weight > '47000' && $weight <= '48000'):
$item['class'] = 'lichtbruin';
case($weight > '48000' && $weight <= '49000'):
$item['class'] = 'bruin';
case($weight > '49000' && $weight <= '50000'):
$item['class'] = 'lichrood';
case($weight > '50000'):
$item['class'] = 'rood';
}
switch($date){
case($date > $s_year.'-'.$quart1 && $date <= $s_year.'-'.$quart2):
$item['quarter'] = '1'; //kwartaal 1
case($date > $s_year.'-'.$quart2 && $date <= $s_year.'-'.$quart3):
$item['quarter'] = '2'; ////kwartaal 2
case($date > $s_year.'-'.$quart3 && $date <= $s_year.'-'.$quart4):
$item['quarter'] = '3'; ////kwartaal 3
case($date > $s_year.'-'.$quart4 && $date <= $s_year.'-'.$end):
$item['quarter'] = '4'; ////kwartaal 4
}
//$item['quarter'] = 1; WHEN I DO THIS, ALL RESULTS WILL PRINT OUT!!!
switch($item['quarter']){
case '1':
print "<tr>\n";
print " <td>" . $item['nrplaat'] . "\n";
print " <td>" . $item['tptcode'] . "\n";
print " <td>" . $item['chrononr'] . "\n";
print " <td>" . $item['projectcode'] . "\n";
print " <td>" . $item['projectnaam'] . "\n";
print " <td>" . $item['1eweging'] . "\n";
print " <td>" . "<span class=\"status\">".$item['class']."</span>" ."\n";
print " <td>" . $item['overweighted'] . "\n";
print " <td>" . $item['date'] . "\n";
print " <td>" . $item['2eweging'] . "\n";
print " <td>" . $item['netto'] . "\n";
print "</tr>\n";
break;
}
}
Use break;
case($date > $s_year.'-'.$quart1 && $date <= $s_year.'-'.$quart2):
$item['quarter'] = '1';
break;
Perhaps it's because you don't have break; in each switch case.
Try to add some break;
See here for switch in php.
You should add a break; statement at the end of each case.
You should add 'break' after 'case'. it is very important if you have some 'case'. Please understand the concept of switch statements, you can learn from http://php.net/manual/en/control-structures.switch.php.
If you have some 'case' and you don't use 'break', it mean the next case will be proceed too. If you using 'break' after 'case', the switch process will finish and not proceed to next case. Maybe you should learn about 'continue' too :)

how to make static index of array in php

I am trying to store values from form radio to array. But problem which i am facing is that every time array 1st index is replaced with new value. I believe this is scope problem. I also tried to declare global array but no success.
Here is the code:
<?php
include_once("connection.php");
$c = new DBcon();
$c->startcon();
global $array; // not effecive
// $q = $_POST['t'];
// echo 'fff', $q;
$page = $_GET['page'];
echo 'pagesss', $page, 'ppp';
if ($page == "") {
$page = "1";
} else {
// If page is set, let's get it
$page = $_GET['page'];
}
// Now lets get all messages from your database
$sql = "SELECT * FROM quizes";
$query = mysql_query($sql);
// Lets count all messages
$num = mysql_num_rows($query);
// Lets set how many messages we want to display
$per_page = "2";
// Now we must calculate the last page
$last_page = $num;
echo 's', $num;
// And set the first page
$first_page = "1";
// Here we are making the "First page" link
echo "<a href='?page=" . $first_page . "'>First page</a> ";
// If page is 1 then remove link from "Previous" word
if ($page == $first_page) {
echo "Previous ";
} else {
if (!isset($page)) {
echo "Previous ";
} else {
// But if page is set and it's not 1.. Lets add link to previous word to take us back by one page
$previous = $page - 1;
echo "<a href='?page=" . $previous . "'>Previous</a> ";
}
}
// If the page is last page.. lets remove "Next" link
if ($page == $last_page) {
echo "Next ";
} else {
// If page is not set or it is set and it's not the last page.. lets add link to this word so we can go to the next page
if (!isset($page)) {
$next = $first_page + 1;
echo "<a href='?page=" . $next . "'>Next</a> ";
} else {
$next = $page + 1;
echo "<a href='?page=" . $next . "'>Next</a> ";
}
}
// And now lets add the "Last page" link
echo "<a href='?page=" . $last_page . "'>Last page</a>";
// Math.. It gets us the start number of message that will be displayed
$start = ($page * ($page - 1)) / $page;
echo 'start', $start;
echo 'page', $page;
// Now lets set the limit for our query
$limit = "LIMIT $start, $per_page";
// It's time for getting our messages
$sql = "SELECT * FROM quizes $limit";
$query = mysql_query($sql);
echo "<br /><br />";
// And lets display our messages
$i = 0;
$l = 0;
while ($row = mysql_fetch_array($query) or die(mysql_error())) {
$a = $row['A'];
echo '<form method="get" action="?page=".$next."">';
while ($row = mysql_fetch_array($query)) {
echo '<div class="boxed" >';
echo "\t" . '<tr><th>' .
$row['question'] . "<br>" .
'</th><th>' . "<input type='radio' name= 't[]' value='{$row['A']}'>" . $row['A'] . "<br>" .
'</th><th>' . "<input type='radio' name='t[]' value='{$row['B']}'>" . $row['B'] . "<br>" .
'</th><th>' . "<input type='radio' name='t[]' value='{$row['C']}'>" . $row['C'] . "<br>" .
'</th><th>' . "<input type='radio' name='t[]' value='{$row['D']}'>" . $row['D'] . '</th>
</tr>';
echo '<input type="hidden" name="page" value="' . $next . '">';
echo '<input type="submit" name="submit"/>';
$i++;
echo '</div>';
echo '</div>';
}
echo '</form>';
if (isset($_GET['submit'])) {
$example = $_GET['t'];
foreach ($example as $value) {
$array[$i++] = ($value);
echo "$array[0] <br>"; // printing correct statement but replacing old values with new value everytime.
echo "$array[1] <br>"; // 0 values
echo "$array[2] <br>"; // 0 values
}
}
}
?>
I have seen these posts: PHP array indexing: $array[$index] vs $array["$index"] vs $array["{$index}"] , PHP - define static array of objects but no help. Kindly help what should i do?
You cannot do
$array[$i++]
this will always be $array[1]
instead do
$i++;
$array[$i]= $value;
P.S. $array is a terrible name for a variable...
if (isset($_GET['submit'])) {
$example = $_GET['t'];
$i=0;
$arrayA = array();
foreach ($example as $value) {
$arrayA[$i] = ($value);
$i++;
}
print_r($arrayA);
}
if you do
$array[$i++] ;
it wont work , just try this and it wont replace your old value
$array[$i] = $value;
$i++;
You must increment your variable first, then use the variable as the array key.
Edit: this is what you're looking for:
$i = 0;
foreach ($example as $value) {
$array[$i] = $value;
$i++;
}

PHP Comparing 0 does not work

I'm trying to set a checkbox as checked in php based on an hour fields from a comma separated value string. It works well for 1-23 but for some reason hour 0 always displays as checked:
<?php
myhours = explode(",", substr($arruser['arhours'],0,strlen($arruser['arhours']) - 1));
$checked = "";
for($hour = 0; $hour <= 23; $hour++) {
if(count($myhours) > 0) {
for($h = 0; $h <= count($myhours); $h++) {
if((int)$hour == (int)$myhours[$h]) {
$checked = " checked ";
break;
}
}
} else {
$checked = "";
}
if(strlen($hour) == 1) {
echo "<td><input type=checkbox " . $checked . " value=" . $hour . " onchange=\"updatehour(" . $_REQUEST['user'] . ",this.checked, '" . $hour . "')\">0$hour:00</td>";
} else {
echo "<td><input type=checkbox " . $checked . " value=" . $hour . " onchange=\"updatehour(" . $_REQUEST['user'] . ",this.checked, '" . $hour . "')\">$hour:00</td>";
}
$checked = "";
}
?>
The problem is straightforward; look at the outer loop:
for ($hour = 0; $hour <= 23; $hour++) {
Consider only the first iteration, so $hour is int(0). Further in the code:
if(count($myhours) > 0) {
for($h = 0; $h <= count($myhours); $h++) {
Pay close attention to the loop condition:
$h <= count($myhours)
Consider the last iteration of that loop, so $h equals the size of your array.
if ((int)$hour == (int)$myhours[$h]) {
At this point $myhours[$h] is undefined because the array index is out of bounds (and a notice would have been emitted) and so (int)$myhours[$h] becomes (int)null which is int(0). The comparison is therefore always true when $hour has the value of int(0).
The solution is to change the loop condition to:
$h < count($myhours)
Not exactly and answer, but your code could be reduced to this:
$myhours = array(0, 10, 13, 20);
for($hour = 0; $hour <= 23; $hour++) {
echo '<td><input type="checkbox"' . ( in_array($hour, $myhours) ? ' checked' : '' ) . ' value="' . $hour . '" onchange="updatehour(' . $_REQUEST['user'] . ', this.checked, ' . $hour . ')">' . str_pad($hour, 2, '0', STR_PAD_LEFT) . ':00</td>';
}
No need for a second loop and more variables here. Also be aware to not output values from $_REQUEST directly without any check.
Demo
Try before buy
Problem solved. It was actually the count($myhours) that was causing the problem. Basically even with an empty string it still returns an array with 1 element. Changed to check if count($myhours) > 1 and everything is working as expected:
<?php
$myhours = explode(",", substr($arruser['arhours'],0,strlen($arruser['arhours']) - 1));
$checked = "";
for($hour = 0; $hour <= 23; $hour++) {
if(count($myhours) > 1) {
for($h = 0; $h <= count($myhours); $h++) {
if((int)$hour == (int)$myhours[$h]) {
$checked = " checked ";
break;
}
}
} else {
$checked = "";
}
if(strlen($hour) == 1) {
echo "<td><input type=checkbox " . $checked . " value=" . $hour . " onchange=\"updatehour(" . $_REQUEST['user'] . ",this.checked, '" . $hour . "')\">0$hour:00</td>";
} else {
echo "<td><input type=checkbox " . $checked . " value=" . $hour . " onchange=\"updatehour(" . $_REQUEST['user'] . ",this.checked, '" . $hour . "')\">$hour:00</td>";
}
$checked = "";
}
?>

PHP: Undefined offset in for loop

While making a photo gallery I encountered a problem. With every photo I try to show how many comments it has, however if a photo has 0 comments it will give me an 'undefined offset' error. I have no idea what I am doing wrong because it does show that there are 0 comments.
This is the code of what is relevant to the problem:
(The problem occurres in the line: if($reacties[$i]==0){)
if((isset($_GET['vanafFoto'])) AND (intval($_GET['vanafFoto']>=0)) AND (intval($_GET['vanafFoto'] < $countFotos))){
$begin = intval($_GET['vanafFoto']);
if(($begin + $aantalFotos) <= $countFotos){
$eind = ($begin + $aantalFotos);
} // end if
else {
$eind = $countFotos;
} // end else
} // end if
else {
$begin = 0;
$eind = $aantalFotos;
} // end else
$countFotos = count($fotoArray);
// path naar echte foto
} // end else
echo "<table border='0' cellpadding='0' cellspacing='2'><tr><td ><b>" . $pathspatie . "</b> <small>(" . $count . ")</small>
<br><br><center><small>Pictures " . ($begin + 1) . " - " . $eind . "</small></center></td></tr></table>";
if(($begin - $aantalFotos) >= 0){
$navigation = "<a href='" . $_SERVER['PHP_SELF'] . "?page=album&boek=" . $originalPath . "&vanafFoto=" . ($begin - $aantalFotos) . "'><</a> " . $navigation;
} // end if
if(($begin + $aantalFotos) < $count){
$navigation .= " <a href='" . $_SERVER['PHP_SELF'] . "?page=album&boek=" . $originalPath . "&vanafFoto=" . ($begin + $aantalFotos) . "'>></a>";
} // end if
echo $navigation . "<br><br>";
echo "</td></tr><tr>";
$fotonr = 1;
for($i=$begin; $i < $eind; $i++){
$thumb = str_replace($path2, $thumbPath, $fotoArray[$i]);
echo "<td align='center'><a href='" . $_SERVER['PHP_SELF'] . "?page=album&boek=" . $originalPath . "&fotoID=" . $i . "'><img border='0' src='" . $thumb . "' height='100'><br>";
echo "<small>reacties (";
if($reacties[$i]==0){ // error occurres here.
echo "0";
} // end if
else {
echo $reacties[$i];
} // end else
echo ")</small>";
echo "</a></td>";
$fotonr++;
if($fotonr == ($clm + 1)){
echo "</tr>\n<tr>";
$fotonr = 1;
} // end if
} // end for
If anyone can see what the problem is it would be great!
I did not understand you exact goal but maybe it is better to write one more check:
if(!isset($reacties[$i]) || $reacties[$i]==0){
echo "0";
}

Categories