array manipulation with foreach

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am trying to make a bit of code that takes values from 2 arrays,

one array has a list of all the date's of this week starting from sunday,

$arraydate[$n] = "the date"

where $n is an integer between 0+6

the other is a multidimensional array composition as such;

$rota[$staffid][$x] = "date staff member is working"

where staffid is a unique id number for each staff member. $x is just a number to denote the second array that stores all the days that staff are working.


The output created by the code is as follows, it is not displaying all the days that every staff member is working... it should have staff member 1 working sunday and tuesday, and staff member 2 working monday and wednesday.


==================================================
<div align="center"><center><table border="1" cellpadding="0"
   cellspacing="0">
       <tr>
           <td>&nbsp;</td>
           <td>Sunday</td>
           <td>Monday</td>
           <td>Tuesday</td>
           <td>Wednesday</td>
           <td>Thursday</td>
           <td>Friday</td>
           <td>Saturday</td>

       </tr>
       <tr>
           <td>Bar</td>
           <td>&nbsp;</td>
           <td>&nbsp;</td>
           <td>&nbsp;</td>
           <td>&nbsp;</td>
           <td>&nbsp;</td>
           <td>&nbsp;</td>
           <td>&nbsp;</td>
       </tr>

<tr><td>2</td>
<td></td><td></td><td></td><td><p align="center"><input type="checkbox" checked name="C1" value="ON"></p></td><td></td><td></td><td></td>
</tr>
</table>


======================================
here is the code i used ( i know it isn't right, but i just don't know how to fix it)


======================================

<?

$weekbeginning = weekbeginningYmd();
$arraydate = createdatearray($weekbeginning);
$rota = getrotafromdb($date);

?>
<form method="POST">
   <p>&nbsp;</p>
   <div align="center"><center><table border="1" cellpadding="0"
   cellspacing="0">
       <tr>
           <td>&nbsp;</td>
			<td>Sunday</td>
           <td>Monday</td>
           <td>Tuesday</td>
           <td>Wednesday</td>
           <td>Thursday</td>
           <td>Friday</td>
           <td>Saturday</td>

       </tr>
       <tr>
           <td>Bar</td>
           <td>&nbsp;</td>
           <td>&nbsp;</td>
           <td>&nbsp;</td>
           <td>&nbsp;</td>
           <td>&nbsp;</td>
           <td>&nbsp;</td>
           <td>&nbsp;</td>
       </tr>

<?
foreach($rota as $staffid => $variable){
?>
<tr><td><? echo $staffid; ?></td>
<?
foreach($arraydate as $key => $date){
?><td><?
foreach($variable as $key2 => $workdate){
if($date == $workdate){
?><p align="center"><input type="checkbox" checked name="C1" value="ON"></p><?
}
}
?></td><?
}
}
?>
</tr>
</table>
</center></div><p>&nbsp;</p>
</form>



_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger



-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux