473,320 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Undefined offset: 2 /Undefined offset: 1 error on line 14

1
this code runs a para type multi choice question.there is 3 question with 4 options each.

if we select all three uestion's answer then there is no error.

if select only one question's answer Undefined offset: 1 error occurs.

if we select any two question's answer Undefined offset: 2 error occurs.












Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.     $options = json_decode($question->answers); 
  3.     $correct_answers = json_decode($question->correct_answers);
  4.  
  5.      $outer_index=0;
  6.  
  7. ?> <div class="row"> <div class="col-md-12"> <ul class="questions-container fullwidth"> <?php foreach($options as $option) { 
  8.             $cAnswer = $correct_answers[$outer_index]->answer;
  9.             $uAnswer = $user_answers[$outer_index++];
  10.              //dd($uAnswer);
  11.              //print_r($option->options[0]);
  12.             $sub_options = (array)$option->options;
  13.  
  14.             foreach($sub_options as $key => $value)
  15.              $sub_options = $value;
  16.             ?> <li> <div class="question"> <h3>{{ $option->question }}</h3> </div> <div class="select-answer"> <ul class="row"> <?php $index=0; 
  17.  
  18.                      foreach($sub_options as $key => $value) { 
  19.                         $correct_answer_class = '';
  20.                         if($cAnswer==$index+1)
  21.                         {
  22.                               $correct_answer_class = 'correct-answer';
  23.                         }
  24.  
  25.                         $submitted_value = '';
  26.                        if($user_answers) 
  27.                        {
  28.                           if($uAnswer == $index+1) 
  29.                           {
  30.                                 $submitted_value = 'checked';
  31.  
  32.                             }
  33.                         }
  34.  
  35.                         ?> <li class="col-md-6 {{$correct_answer_class}} answer_radio" > <input type="radio" name="option{{$question->id.$outer_index}}" id="1radio1"  {{$submitted_value}} disabled=""> <label for="1radio1"> <span class="fa-stack radio-button"> <i class="mdi mdi-check active"></i> </span> {{ $value}}  </label> </li> <?php $index++; } ?> </ul> </div> </li> <hr> <?php } ?> </ul> </div> </div>
Sep 30 '19 #1
0 1566

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: google | last post by:
Hello, I'm having major problems trying to get my head round this problem. I'm trying to generate an error free script, however, I still cannot sort out this loop. I get a "Notice:...
3
by: delusion7 | last post by:
I am getting this error "Undefined offset: 9 in C:\Course Technology\1687-5\Chapter.10\UpdateContactInfo.php on line 36" this is the code I am recieving the error on: if...
7
by: rwaller | last post by:
Works fine in IE, but not in Firefox? Code below, thank you in advance.... http://www.cnusd.k12.ca.us/roosevelt%2Dhs/Leaving_Site/leavingERHSpavelgcy.html <SCRIPT LANGUAGE=vbscript> function...
9
by: simple12 | last post by:
Hello I have a script which have the facility of entering any code to some part of a webpage. I have some problems with it. When i put some code in the script then their is no error shown. When i...
6
by: raydiamond4u | last post by:
Hello. My name is Raymond. My code is generating the following error: Notice: Undefined offset: 2 in C:\wamp\www\imagegallery\supportfile\include\config.php on line 25 How do i correct the error?...
1
by: Mary meer | last post by:
i am trying to switch array value but i get this error message: Undefined offset 2 $at=array( array('Title:','title',2,10), array('First Name:','fname',2,10 ), ...
6
by: tbebest | last post by:
Hi , i have a form and it has A problem: i upload my 3 image and it uploaded in definded path but in insert in db filed there are empty: Notice: Undefined offset: 0 in C:\wamp\www Notice:...
4
by: Kevon | last post by:
Hello, I'm designing a photo gallery for my website, I've followed several tutorials online about how to go about doing this, with great success, I have come up with a set of codes, however I keep...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.