mysql -> array question
Posted: Fri Feb 22, 2008 8:07 am
Mod | Please use [ php], [ code ] and [ syntax="..." ] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi all,
I am new to php and mysql and I am trying to create a calender with a checkbox next to each number. In addition, I am trying to make a check whether a day has been booked and to display the calendar checkbox checked if it is. So what i do is a function where I put the result from the DB into an array but I am having a problem using this array outside the function for an external check. here is some code to see what I am doing wrong:
everything I think works except for .... it doesn't check anything. Any help is welcome. Thanks
Mod | Please use [ php], [ code ] and [ syntax="..." ] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi all,
I am new to php and mysql and I am trying to create a calender with a checkbox next to each number. In addition, I am trying to make a check whether a day has been booked and to display the calendar checkbox checked if it is. So what i do is a function where I put the result from the DB into an array but I am having a problem using this array outside the function for an external check. here is some code to see what I am doing wrong:
Code: Select all
function res(){
$sql = "SELECT * FROM calendar_field";
$query = mysql_query($sql);
if ($query){
while($row = mysql_fetch_assoc($query)) {
$check[] = $row['date'];
}
return $check;
}
return true;
}
$checkdate = res();
print_r($checkdate); // just to see what it returns
for ($i=1; $i<=$days; $i++){
?>
<td class='cal'><?php echo $i; ?><br /><input type='checkbox' name='month[<?php echo $i; ?>]'
<?php
if ($i == $checkdate) {
echo " checked /></td>";
}else{
echo "/></td>";}
}
Code: Select all
if ($i == $checkdate)Mod | Please use [ php], [ code ] and [ syntax="..." ] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: