$q1 = mysql_query("select in_time, out_time from $att_tbl where fk_eid = '$e_id' and a_date = '$dts'");
$r1 = mysql_fetch_array($q1);
$intime = $r1['in_time'];
$outtime = $r1['out_time'];
In the above code ‘$e_id’ is a normal id used to specify users and ‘$dts’ is date in the format YYYY-MM-DD . But when i use this code it halts my parent while loop and if i comment this code my while loop runs fine. I have never seen such behavior. Why is this happening? What is wrong with this code ?
EDIT : this is the full rough code
$q1 = mysql_query("select ids from $emp_data where lft = '0' order by emp_id");
while($r1 = mysql_fetch_array($q1))
{
$e_id = $r1['ids'];
$htmldata = '';
$filename = "$e_id-$months-$years.html";
$date =time () ;
$day = date('d', $date) ;
$month = date('m', $date) ;
$year = date('Y', $date) ;
$first_day = mktime(0,0,0,$month, 1, $year) ;
$title = date('F', $first_day) ;
$day_of_week = date('D', $first_day) ;
$today = date('Y-m-d', strtotime('today'));
$yesterday = date('Y-m-d', strtotime('yesterday'));
$day_before_yesterday = date('Y-m-d', strtotime('yesterday - 1 day'));
switch($day_of_week)
{
case "Sun": $blank = 0; break;
case "Mon": $blank = 1; break;
case "Tue": $blank = 2; break;
case "Wed": $blank = 3; break;
case "Thu": $blank = 4; break;
case "Fri": $blank = 5; break;
case "Sat": $blank = 6; break;
}
$days_in_month = cal_days_in_month(0, $month, $year) ;
$htmldata.="<link rel=\"stylesheet\" href=\"/cal.css\" type=\"text/css\"><table id=\"mct1\" class=\"ct1 cl1 cp4 cd2 mct\" cellspacing=0>";
$htmldata.="<tr><th> $title $year </th></tr>";
$htmldata.="<tr><td class=\"cbm cba cmi\"><table class=\"ca ca2\"><tr class=\"cl\"><td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td class=\"cr\">Sat</td></tr>";
$day_count = 1;
$htmldata.="<tr>";
while ( $blank > 0 )
{
$htmldata.="<td> </td>";
$blank = $blank-1;
$day_count++;
}
$day_num = 1;
while ( $day_num <= $days_in_month )
{
$dts = date("Y-m-d", strtotime("$year-$month-$day_num"));
if(strtotime($dts) <= strtotime($today))
{
// $q1 = mysql_query("select in_time, out_time from $att_tbl where fk_eid = '$e_id' and a_date = '$dts'");
// $r1 = mysql_fetch_array($q1);
// $intime = $r1['in_time'];
// $outtime = $r1['out_time'];
}
$bgclr = '';
$weekday = date('D', strtotime($year."-".$month."-".$day_num));
if($weekday == 'Sun')
{
$bgclr = "bgcolor = \"pink\"";
}
$htmldata.="<td class=\"cr\" $bgclr><div class=\"ccd co4\">$day_num <br><font size=\"2\"> $intime <br> $outtime </font></div></td>";
$day_num++;
$day_count++;
if ($day_count > 7)
{
$htmldata.="</tr><tr>";
$day_count = 1;
}
}
while ( $day_count >1 && $day_count <=7 )
{
$htmldata.="<td> </td>";
$day_count++;
}
$htmldata.="</tr></tbody></table></td></tr></table>";
$myFile = "$filename";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $htmldata;
fwrite($fh, $stringData);
fclose($fh);
}
I have commented the code that is halting the whole while loop so that it can be easily seen
Your script could have been halted due to the fact that
in_timeandout_timedo not exist in your array. Otherwise, there is no problem to your query unless you tell us what you have been assigning to the variables.As I have mentioned in the comments, check in the
error_logfile, which resides in the same directory as this PHP script.Also, is your parent loop also something along the lines of:
while ($foo = @mysql_fetch_array($q1))If it is, then that might be your error. You are resetting the value of
$q1inside the while loop, therefore possibly terminating the loop.UPDATE: Now that you posted your code, I know your exact error:
These are your first two lines of code, used to run the main
whileloop:Notice that you used
$q1to reference the query. Now down in that piece of code, inside a nestedwhileloop:You used
$q1again. The interpreter thought that you meant to change the variable value, but instead you wanted to initialize another variable called$q1.Okay, after all that, all you need to do is write this for your code:
And just change your references anywhere else.