Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Error: Trying to access array offset on value of type bool

Asked Modified Viewed 2,139 times
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
asked
Senior Member

I have done some web research and cannot seem to find how to solve this. Code is from my 'grims_blog infusion', in 'calendar.php' script.
Here is the code:
for ($d=1; $d<=$endDate; $d++) {
if (date('w',mktime (0,0,0,$cMonth,$d,$cYear)) == 0) { echo "<tr>\n"; }
$result = dbquery("SELECT * FROM ".DB_GRIMS_BLOG_POST." WHERE active='1' AND MONTH(post_date) = '$cMonth' AND DAY(post_date) = '$d'");
$data = dbarray($result);
      $id = $data['post_id'];
      $title = $data['post_title'];
      $evday = strtotime($data['post_date']); /*THIS LINE IS CAUSING THE ERROR*/
if (date("d", $evday) == $d) {

Any help would be appreciated. This section of code selects days with events.
0 replies

16 posts

G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

This is the entire FOR LOOP that identifies the days of the month that have events. It actually works just fine and links the event days in my calendar as I want it to. I have modified the query output coding but still get the same error/results:
for ($d=1; $d<=$endDate; $d++) {
if (date('w',mktime (0,0,0,$cMonth,$d,$cYear)) == 0) { echo "<tr>\n"; }
$result = dbquery("SELECT post_id, post_title, post_date FROM ".DB_GRIMS_BLOG_POST." WHERE active='1' AND MONTH(post_date) = '$cMonth' AND DAY(post_date) = '$d'");
$data = dbarray($result);
      if($data['post_id'] == false || is_null($data['post_id'])) {
         $id = ''; } else { $id = $data['post_id']; }

      if($data['post_title'] == false || is_null($data['post_title'])) {
         $title = ''; } else { $title = $data['post_title']; }

      if(strtotime($data['post_date']) == false || is_null(strtotime($data['post_date']))) {
         $evday = ''; } else { $evday = strtotime($data['post_date']); }

if (date("d", $evday) == $d) {
echo "<td height='35' class='event' align='center' valign='middle'>\n";
} elseif ($d == $day && $cMonth == date('m')) {
echo "<td height='35' class='today' align='center' valign='middle'>\n";
} else {
echo "<td height='35' class='cal-norm' align='center' valign='middle'>\n";
}
if ($d == $day && $cMonth == date('m') && $d <> $evday) {
echo "<a class='cal2' href='#' title='".$locale['gb_513']."'><b>$d</b></a>\n";
} elseif ($d == $day && $cMonth == date('m') && $d == $evday) {
echo "<a class='cal2' href='#' title='".$locale['gb_513']." - $title'><b>$d</b></a>\n";
} elseif ($evday) {
echo "<a class='ecal' href='".BASEDIR."grims_blog/filtered.php?post_id=$id' title='$title'><b>$d</b></a>\n";
} else {
echo "<span class='noevt'><b>$d</b></span>\n";
}

This is really driving me insane(as if I wasn't already), could someone please take a look at this and help me?
Fusion 9.03.110
PHP Ver 7.4.16
Edited by Grimloch on 15-04-2021 16:13,
0 replies
F
Falk
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
answered
Super Admin

In PHP 7.4+ You can not do if statements on empty / not defined strings. so for example ..
} elseif ($evday) {
if the $evday is empty you will get that error, you need default values defined on all if instances that try to access an array
prfferable ternary methods.
like $evday = $data['data'] ? $data['data'] : 'default value';

So you are on the right track here but need to make some more checks.

if(strtotime($data['post_date']) == false || is_null(strtotime($data['post_date']))) {
$evday = ''; } else { $evday = strtotime($data['post_date']); }
1 reply
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

I've done some reading and I'm still not quite sure how to implement this Falk. This is what I tried:
$result = dbquery("SELECT post_id, post_title, post_date FROM ".DB_GRIMS_BLOG_POST." WHERE active='1' AND MONTH(post_date) = '$cMonth' AND DAY(post_date) = '$d'");
$data = dbarray($result);
 if($data['post_id'] == false || is_null($data['post_id'])) {
   $id = $data['post_id'] ? $data['post_id'] : 'default value';
 $id = ''; } else { $id = $data['post_id']; }

 if($data['post_title'] == false || is_null($data['post_title'])) {
   $title = $data['post_title'] ? $data['post_title'] : 'default value';
 $title = ''; } else { $title = $data['post_title']; }

 if(strtotime($data['post_date']) == false || is_null(strtotime($data['post_date']))) {
   $evday = $data['post_date'] ? $data['post_date'] : 'default value';
 $evday = ''; } else { $evday = strtotime($data['post_date']); }

...and the result is the same, The error is the same.
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

I reduced the code to the bare minimum and STILL have the error:
for ($d=1; $d<=$endDate; $d++) {
if (date('w',mktime (0,0,0,$cMonth,$d,$cYear)) == 0) { echo "<tr>\n"; }
$result = dbquery("SELECT post_id, post_title, post_date FROM ".DB_GRIMS_BLOG_POST." WHERE active='1' AND MONTH(post_date) = '$cMonth' AND DAY(post_date) = '$d'");
$data = dbarray($result);

   $stuff1 = $data['post_id'] ? $data['post_id'] : ''; /* ERROR LINE */
   $id = $stuff1;

   $stuff2 = $data['post_title'] ? $data['post_title'] : ''; /* ERROR LINE */
   $title = $stuff2;

   $stuff3 = strtotime($data['post_date']) ? strtotime($data['post_date']) : ''; /* ERROR LINE */
   $evday = $stuff3;

if (date("d", intval($evday)) == $d) {
echo "<td height='35' class='event' align='center' valign='middle'>\n";
} elseif ($d == $day && $cMonth == date('m') && $cYear == date('Y')) {
echo "<td height='35' class='today' align='center' valign='middle'>\n";
} else {
echo "<td height='35' class='cal-norm' align='center' valign='middle'>\n";
}
if ($d == $day && $cMonth == date('m') && $d <> $evday) {
echo "<a class='cal2' href='#' title='".$locale['gb_513']."'><b>$d</b></a>\n";
} elseif ($d == $day && $cMonth == date('m') && $d == $evday) {
echo "<a class='cal2' href='#' title='".$locale['gb_513']." - $title'><b>$d</b></a>\n";
} elseif ($evday) {
echo "<a class='ecal' href='".BASEDIR."grims_blog/filtered.php?post_id=$id' title='$title'><b>$d</b></a>\n";
} else {
echo "<span class='noevt'><b>$d</b></span>\n";
}
echo "</td>\n";
if (date('w',mktime (0,0,0,$cMonth,$d,$cYear)) == 6) { echo "</tr>\n"; }
}

Incredibly frustrating; I'm beginning to really HATE the way they keep UPGRADING the php versions w/o backward compatibilities.
Sure I could change the active php version but that would screw up other things. What a dilemma!! Where do I go from here???
0 replies
R
Anonymous User
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions
answered
Veteran Member

Did you tried dbrows($result) ? These errors obviously occur when you loading something that does not exist.

$result = dbquery("SELECT post_id, post_title, post_date FROM ".DB_GRIMS_BLOG_POST." WHERE active='1' AND MONTH(post_date) = '$cMonth' AND DAY(post_date) = '$d'");
if (dbrows($result) > 0) {
$data = dbarray($result);
 $id = $data['post_id'];
 $title = $data['post_title'];
 $evday = strtotime($data['post_date']);
}
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

Yes I did and I can't do that because that portion of my script (with the query) is already in a for loop. Here is the result of doing that: image attached. It makes every day of the calendar a link.
Grimloch attached the following image:
Image not found
0 replies
D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

Does the error occur in every pass of the for loop or only if the result of the query is empty because there are no records matching the condition DAY(post_date) = '$d'"wink;
?
If you only get the error when there are no results, you maybe you can do some pre-filtering on the for-loop condition.
1 reply
D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

What I mean:

The query with data given troubles is executed in a for loop.
So when the script is executed, the query is executed x-times.

But if there are no records for a given day, the results of that query is empty
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

The $d 'for loop' is executed 30 times for the month of April and prints the days of the month in the calendar. Only 2 matches are found by the query for the month of April. The first is the event that was posted on the 1st of April and the second is the current day of the month. For every other day in the month the query finds nothing. So I don't really know how to handle that.
0 replies
D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

Then I would say change your query, fetch all days with data only, sort it on day, put it in an array, and loop through the array to echo the results. Advantage is you only need 1 query in stead of 30.

Of course it need some work to put it on the right way in some sort of array structure.
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

I'll have to think about that and see if I can figure out how to do it. Thanks for the suggestion I'll report back here.
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

Well I've thought about it, done some more research and tried several scenarios. It just will not work unless the db query is INSIDE the for loop. This is a calendar script that I put together years ago in the Fusion7 days and it works great as is. So I guess this one is a stalemate. You guys can close this thread because there is no answer to be gleaned here. Thanks for the help.
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

Hey guys. With some help from PHP Freaks I have now solved this problem. Here is the solution coding:
$data = dbarray($result);
   if (empty($data['post_id'])) {
      $id = null;
   } else { $id = $data['post_id']; }
   if (empty($data['post_title'])) {
      $title = null;
   } else { $title = $data['post_title']; }
   if (empty($data['post_date'])) {
      $evday = null;
   } else { $evday = strtotime($data['post_date']); }

OK guys this an alternate method and it still works just fine. Slightly less code.
$data = dbarray($result);
   if (!$data) {
      $id = null; $title = null; $evday = null;
   } else {
      $id = $data['post_id'];
      $title = $data['post_title'];
      $evday = strtotime($data['post_date']);
   }
Edited by Grimloch on 20-04-2021 00:32,
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

Well I'm at it again folks. I need some help in figuring out where to put this code in my calendar script. What I am trying to do is pad all single digit days of the month with a zero. i.e. 1 would be 01 etc. etc. I know the correct code to use just not where to place it in the FOR loop.
for ($d=1; $d<=$endDate; $d++) {

// begin added code
$padd = $d;
$padd = str_pad($padd, 2, '0', STR_PAD_LEFT);
echo $padd;
// end of added code

if (date('w',mktime (0,0,0,$cMonth,$d,$cYear)) == 0) { echo "<tr>\n"; }
$result = dbquery("SELECT post_id, post_title, post_date FROM ".DB_GRIMS_BLOG_POST." WHERE active='1' AND MONTH(post_date) = '$cMonth' AND DAY(post_date) = '$d'");
$data = dbarray($result);
   if (!$data) {
      $id = null; $title = null; $evday = null;
   } else {
      $id = $data['post_id'];
      $title = $data['post_title'];
      $evday = strtotime($data['post_date']);
   }
if (date("d", intval($evday)) == $d) {
echo "<td height='35' width='35' class='event' align='center' valign='middle'>\n";
} elseif ($d == $day && $cMonth == date('m') && $cYear == date('Y')) {
echo "<td height='35' width='35' class='today' align='center' valign='middle'>\n";
} else {
echo "<td height='35' width='35' class='cal-norm' align='center' valign='middle'>\n";
}
if ($d == $day && $cMonth == date('m') && $d <> $evday) {
echo "<a class='cal2' href='#' title='".$locale['gb_513']."'><b>$d</b></a>\n";
} elseif ($d == $day && $cMonth == date('m') && $d == $evday) {
echo "<a class='cal2' href='".BASEDIR."grims_blog/filtered.php?post_id=$id' title='$title'><b>$d</b></a>\n";
} elseif ($evday) {
echo "<a class='ecal' href='".BASEDIR."grims_blog/filtered.php?post_id=$id' title='$title'><b>$d</b></a>\n";
} else {
echo "<span class='noevt'><b>$d</b></span>\n";
}
echo "</td>\n";
if (date('w',mktime (0,0,0,$cMonth,$d,$cYear)) == 6) { echo "</tr>\n"; }
}

Here is an image of the result of where it is now and as you cann see the output is correct.
Edited by Grimloch on 21-04-2021 19:48,
Grimloch attached the following image:
Image not found
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

Nevermind guys I figured it out. Here is the answer:
for ($d=1; $d<=$endDate; $d++) {
if ($d < 10) {
 $d = str_pad($d, 2, "0", STR_PAD_LEFT);
};

Works great!
1 reply
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

That's an older calendar script which has some flaws. The one you need to look at is here:
https://blog.whisperwillow.net/grims_.../index.php
It's not a plug-in and won't work outside of my infusion which I'm not prepared to share with the community just yet. Sorry.
0 replies

Labels

Statistics

  • Views 0 views
  • Posts 16 posts
  • Votes 0 votes
  • Topic users 5 members

5 participants

F
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
G
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
D
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
R
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions
A
A
PHP-FUSION ARABIC SUPPORT
http://phpfusion-ar.xyz
 
  • Member, joined since
  • Contributed 96 posts on the community forums.
  • Started 39 threads in the forums

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet