How to concate for loop with html in php

<?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++){
					if($chunk[$i][0] === $days[$i]){
						echo'<tr>
							<td>
								<div class=" form-check" style="margin-top: 7px;">
									<input class="form-check-input" type="checkbox" name="days[]" value="'.$chunk[$i][0].'" checked="checked">
									'.$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="'.$chunk[$i][0].'_Morning_time" title="Select Timings" multiple data-max-options="2"  data-size="5" >';
												for($i=$startTime;$i<=$endTime;$i = $i + 30*60){echo'<option value="'.date('H:i',$i).'">'.date('H:i',$i).'</option>'};
											'</select>
										</div>
										<div class="col-sm-6">
											<label>Evening Timings</label><br>
											<select class="selectpicker" id="'.$chunk[$i][0].'_Evening_time" title="Select Timings" multiple data-max-options="2" data-size="5">';
												for ($i=$startTime;$i<=$endTime;$i = $i + 30*60){'<option value="'.date('H:i',$i).'">'.date('H:i',$i).'</option>'};		
											'</select>
										</div>
									</div>
								</div>			
							</td>
						</tr>';
					}
				}
			?>

How does the code look in the editor you’re using and are you using a proper IDE that has proper syntax highlighting?

Reason I ask is that your editor should point out some obvious syntax errors here`

Echoing an empty string makes no sense echo ''

A few of your echos are missing the ending semicolon.

For loops do not need a semicolon after the closing curly brace.

Wild string ‘Evening Timings’ appears!
Wild string ‘’ appears!

<?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++)
{
    if ($chunk[$i][0] === $days[$i])
    {
        echo '' . $chunk[$i][0] . 'Morning Timings';
        for ($i = $startTime;$i <= $endTime;$i = $i + 30 * 60)
        {
            echo '' . date('H:i', $i) . ''
        };
        'Evening Timings';
        for ($i = $startTime;$i <= $endTime;$i = $i + 30 * 60)
        {
            '' . date('H:i', $i) . ''
        };
        '';
    }
} ?>

Thanks for your valuable reply. at this time i am using sublime 3

Yeah that’s a glorified notepad out of the box. If you want it to help you with code you’d have to install a few plugins and set them up. I suggest you try PHPStorm just to see what your editor CAN do for you and then consider if you want to have the ultra-sleek experience with Sublime, if you want to set it up to something resembling an IDE, or just use an IDE from the start…

Thanks for guiding me I am newbie to PHP and learning own my own. I will try PHPStorm
.

Sponsor our Newsletter | Privacy Policy | Terms of Service