$ar = array(
array('id' => 1, 'title' => '开会', 'startdate' => '2011-8-22 05:15:00'),
array('id' => 2, 'title' => '大扫除', 'startdate' => '2011-8-22 15:30:00'),
array('id' => 3, 'title' => '爱干啥干啥', 'startdate' => '2011-8-22 19:27:45'),
);
我想要把查询出来的数据存到一个数组里,数组如上...------
$result=$mysqli_query("select id,title,startdate from workplan ");
$ar2=array();
while ($rows=mysqli_fetch_array(result))
{
$ar2[]=$rows;
}
我这样存入数组的话,输出怎么是这样的啊...
Array ( [0] => Array ( [0] => 44 [id] => 44 [1] => 开会 [title] => 开会 [2] => 2011-08-21 00:00:00 [startdate] => 2011-08-21 00:00:00 ) [1] => Array ( [0] => 45 [id] => 45 [1] => 大扫除 [title] => 大扫除 [2] => 2011-08-21 00:00:00 [startdate] => 2011-08-21 00:00:00 ) )
array('id' => 1, 'title' => '开会', 'startdate' => '2011-8-22 05:15:00'),
array('id' => 2, 'title' => '大扫除', 'startdate' => '2011-8-22 15:30:00'),
array('id' => 3, 'title' => '爱干啥干啥', 'startdate' => '2011-8-22 19:27:45'),
);
我想要把查询出来的数据存到一个数组里,数组如上...------
$result=$mysqli_query("select id,title,startdate from workplan ");
$ar2=array();
while ($rows=mysqli_fetch_array(result))
{
$ar2[]=$rows;
}
我这样存入数组的话,输出怎么是这样的啊...
Array ( [0] => Array ( [0] => 44 [id] => 44 [1] => 开会 [title] => 开会 [2] => 2011-08-21 00:00:00 [startdate] => 2011-08-21 00:00:00 ) [1] => Array ( [0] => 45 [id] => 45 [1] => 大扫除 [title] => 大扫除 [2] => 2011-08-21 00:00:00 [startdate] => 2011-08-21 00:00:00 ) )
$ar2=array();
while ($rows=mysqli_fetch_assoc(result))
{
$ar2[]=$rows;
}foreach($ar2 as $v)
$r[date('G', strtotime($v['startdate']))] = $v;
}
for($i=7; $i<18; $i++)
{
$re.=sprintf("<tr><td width=\"150px\""."%02d:00 %s<br>"."</td>",$i, $r[$i] ? "<td><a href=\"index.php?action=showputongXiangxi&id=".$r[$i]['id']."&type=putong\">".$r[$i]['title']."</a></td></tr>" : "<td></td></tr>");}我数据库里的数据:如下
编号 标题 开始时间
1 测试1 “2011-8-23 10:00:00”
2 测试2 “2011-8-23 10:00:00”
3 测试3 “2011-8-23 15:00:00”现在已经可以绑定到日视图上,可是“测试1”和“测试2”的开始时间都是重复的,用前辈们提供给的方法,它只能把”测试2“显示到日视图上,但是我需要把它们都显示出来,中间可以用“|”隔开,这个问题要怎么解决啊...
foreach($ar2 as $v){
if(!$r[date('G', strtotime($v['startdate']))])
$r[date('G', strtotime($v['startdate']))] = $v;
else
$r[date('G', strtotime($v['startdate']))]['title'].='|'.$v['title'];
}
标题要加上超链接的,所以需要在显示的时候分开啊,就好比这样
<a href=\"index.php?id=1\">测试1</a> | <a href=\"index.php?id=2\">测试2</a>
while ($rows=mysqli_fetch_assoc(result))
{
$ar2[date('G', strtotime($rows['startdate']))][] = $rows; //读出时就处理
}for($i=7; $i<18; $i++)
{
$re .= sprintf("<tr><td width=\"150px\""."%02d:00 %s</td><td>",$i);
if($ar2[$i]) {
$ch = '';
foreach($ar2[$i] as $v) {
$re .= "$ch<a href=\"index.php?action=showputongXiangxi&id=$v[id]&type=putong\">$v[title]</a>";
$ch = '|';
}
}
$re .= "</td></tr>";
}
报了这个错啊Warning: sprintf() [function.sprintf]: Too few arguments in D:\xampp\htdocs\oa_system\workplan\function.php on line 2062