我有一个数据库,其中包含特定年份的某些事件,例如同年的3或4个事件。我的桌子是这样的:
year | event
-----------------
2004 | Event 1
2004 | Event 2
2005 | Event 3
2005 | Event 4
我想像这样显示它们:
2004
- Event 1
- Event 2
2005
- Event 1
- Event 2
有什么想法吗?非常感谢你!
这是我的实际简单查询:
$result = mysqli_query($con,"SELECT * FROM expos WHERE activo = 1 ORDER BY anio");
echo "<ul id=\"expos\">";
while($row = mysqli_fetch_array($result)){
echo "<li>";
echo $row['anio']."<br />";
echo $row['titulo'];
echo "</li>";
}
echo "</ul>";
mysqli_close($con);
答案 0 :(得分:0)
你正在进行查询!
我认为如果你可以在这个新的阵营中添加一天。查询最容易。
你只需要订购它,但如果你有一天可以做到这一点:
while($row = mysqli_fetch_array($result)){
if($back==$row["anio"] || $back==""){
$var_array[] = $row["evento"];
}
if($back!=$row["anio"]){
foreach($var_array as &$item){
$number=explode(" ",$item);
$number_event[] =$number;
//this is for getting just the number.
}
//bubble sort both are for ordering the array event!.
//shell sort
//here just display with foreach and echo
$back = $row["anio"];
}
}
见到你!