How to concate for loop with html

Is there any one who can help me out with concatination

<?php  
				date_default_timezone_set("Asia/Kolkata");
				$startTime = strtotime(date("H:i:s",strtotime('00:00:00')));
				$endTime = strtotime(date('H:i:s',strtotime('23:59:00')));
				$days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
				$doc_id ='921007GAURAV984934'; 
				$hp_id = 'INRJAPPO2E381F220220';
				$stmt = $con->prepare('SELECT * FROM tb_doc_loc WHERE doc_id=? AND hp_id= ?');
				$stmt->bind_param('ss',$doc_id,$hp_id);
				$stmt->execute();
				$res = $stmt->get_result();
				while($row = $res->fetch_array()){
					$data =  $row['datas'];
				}
				$datas = explode(',',$data);
				$chunk = array_chunk($datas,5);
				for($i=0;$i<count($chunk);$i++):?>
					<?php if($chunk[$i][0] == $days[$i]):?>
						<tr>
							<td>
								<div class=" form-check" style="margin-top: 7px;">
									<input class="form-check-input" type="checkbox" name="days[]" value="<?php echo $chunk[$i][0]?>" checked="checked">
									<?php echo $chunk[$i][0]?> 
								</div>
							</td>
							<td>
								<div class="form-group">
									<div class="row">
										<div class="col-sm-6">
											<label>Morning Timings</label><br>
											<select class="selectpicker " id="<?php echo $chunk[$i][0]?>_Morning_time" title="Select Timings" multiple data-max-options="2"  data-size="5">
												<?php for($i=$startTime;$i<=$endTime;$i = $i + 30*60):?>
													<option value="<?php echo date('H:i',$i);?>"><?php echo date('H:i',$i)?></option>
												<?php endfor;?>
											</select>
										</div>
										<div class="col-sm-6">
											<label>Morning Timings</label><br>
											<select class="selectpicker" id="<?php echo $chunk[$i][0]?>_Morning_time" title="Select Timings" multiple data-max-options="2"  data-size="5">
												<?php for($i=$startTime;$i<=$endTime;$i = $i + 30*60):?>
													<option value="<?php echo date('H:i',$i);?>"><?php echo date('H:i',$i)?></option>
												<?php endfor;?>
											</select>
										</div>
									</div>
								</div>			
							</td>
						</tr>
					<?php endif;?>
				<?php endfor;?>
				<?php for($j=$i;$j<count($days);$j++):?>
				<tr>
					<td>
						<div class=" form-check" style="margin-top: 7px;">
							<input class="form-check-input" type="checkbox" name="edit_days" value="<?php echo $days[$j]?>"><?php echo $days[$j]?>
						</div>
					</td>
					<td>
						<div class="row">
							<div class="col-sm-6">
								<div class="form-group">
									<label >Morning Start</label>
									<select class="selectpicker " id="<?php echo $days[$j]?>_Morning_time" title="Select Timings" multiple data-max-options="2"  data-size="5">
									<?php for($k=$startTime;$k<=$endTime;$k = $k + 30*60){
										echo '<option value="'.date('H:i',$k).'">'.date('H:i',$k).'</option>';
									}?>
									</select>
								</div>	
							</div>
							<div class="col-sm-6">
								<div class="form-group">
									<label >Morning End</label>
									<select class="selectpicker " id="<?php echo $days[$j]?>_Morning_time" title="Select Timings" multiple data-max-options="2"  data-size="5" >
									<?php for($k=$startTime;$k<=$endTime;$k = $k + 30*60){
										echo '<option value="'.date('H:i',$k).'">'.date('H:i',$k).'</option>';
									}?>
									</select>
								</div>
							</div>
						</div>
					</td>
				<?php endfor;?>

Maybe, if you tell us what the problem is?

This is the error [05-Mar-2020 13:45:57 Asia/Kolkata] PHP Notice: Undefined offset: index2.php on line 73

I want to print bootstrap selectpicker by using data base if particular day is present in data base that day will print with checked checkbox after that rest remaining days
problem is only monday is printing

And which is line 73, in the code you posted?

After second label

“undefined offset” means the key you requested does not exists in the array provided. So on your line you are asking for two keys: $chunks[$i][0] one of them fails. You can look at them with var_dump() and compare them with the real keys in $chunks. But i wonder why you are overwring the $i counter from the outer loop with some startTime.

A simple comment in the code you posted would be more helpful than a tiny image.

Yes, well spotted, that won’t help matters. By the time it reaches line 73, it’s already been through the first loop and $i will have a very large value, given that it increments by 1800 each time it goes around.

@droopsnoot got it and not it is working

One more thing if any one can guide me through how can i dynamically select and show the time in bootstrap selectpicker

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.