PHP - 如何使用两个数组的 foreach 循环来构建网格而不在行中重复值
我正在尝试建立一个办公室预约网格。 每行只应列出每个员工(用户)一次。 但每一列都应该代表一个约会。 用户的预约数量将不断变化。我的查询当然会为每个返回一行。我尝试的每一种方法最终都会为每个用户排成一行,每行只有一个约会。
我的数组
$users[] = array ('id' => $row ['id'], 'fname' => $row ['fname']);
输出:
Array (
[0] => Array ( [id] => 1 [fname] => Brent )
[1] => Array ( [id] => 2 [fname] => Macy )
)
$appointments[] = array('id' => $row['id'], 'clientid' => $row['clientid'], 'userid' => $row['userid'], 'date' => $row['date']);
输出:
Array (
[0] => Array ( [id] => [clientfname] => [userid] => [date] =>)
[1] => Array ( [id] =>10 [clientfname] =>Lisa [userid] =>1 [date] =>2011-11-10 1:00:00)
[2] => Array ( [id] =>11 [clientfname] =>Amanda [userid] =>1 [date] =>2011-11-10 1:03:00)
[3] => Array ( [id] =>12 [clientfname] =>Britany [userid] =>2 [date] =>2011-11-10 1:00:00)
)
(Employee Calendar)
<< Monday Oct 8 >>
<< 1:00pm 1:30pm 2:00pm 2:30pm >>
Macy Lisa Amanda
Vanessa Britany
有什么想法吗???
I am trying to build an office appointment Grid.
Each row should only list each employee(user) ONCE.
But each column should represent an appointment.
Users will have an ever changing number of appointments. My query will of course return a row for each. Every way I try this ends up in a row for each user with only one appointment on each row.
My arrays
$users[] = array ('id' => $row ['id'], 'fname' => $row ['fname']);
output:
Array (
[0] => Array ( [id] => 1 [fname] => Brent )
[1] => Array ( [id] => 2 [fname] => Macy )
)
$appointments[] = array('id' => $row['id'], 'clientid' => $row['clientid'], 'userid' => $row['userid'], 'date' => $row['date']);
output:
Array (
[0] => Array ( [id] => [clientfname] => [userid] => [date] =>)
[1] => Array ( [id] =>10 [clientfname] =>Lisa [userid] =>1 [date] =>2011-11-10 1:00:00)
[2] => Array ( [id] =>11 [clientfname] =>Amanda [userid] =>1 [date] =>2011-11-10 1:03:00)
[3] => Array ( [id] =>12 [clientfname] =>Britany [userid] =>2 [date] =>2011-11-10 1:00:00)
)
(Employee Calendar)
<< Monday Oct 8 >>
<< 1:00pm 1:30pm 2:00pm 2:30pm >>
Macy Lisa Amanda
Vanessa Britany
Any ideas????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
例如:
我是第一个承认可能有更简洁的解决方案的人。也许如果您发布了从哪里获取这些数据,那么那里也可以做一些事情。但这应该有效。
For example:
I'd be the first to admit that there might be a neater solution. Perhaps if you had posted where you got this data from, something could be done there too. But this should work.