dongtang1944 2013-05-26 11:41
浏览 27
已采纳

以适当的方式显示mysql with while和foreach

Im trying to display this table:

enter image description here

(To clarify: Uren = Hours, Maandag = Monday, Dinsdag = Tuesday, Woensdag = Wednesday, Donderdag = Thursday, Vrijdag = Friday.

Now im planning to show all data like this in different tables, on the same page in a some kind of "list":

Monday 
Hours: Monday   
1.     Index
2.     Index
3.     Index
4.     Index
5.     Index
6.     Index
7.     Index
8.     Index

  Tuesday
 etc. etc.

Same for all other days~

Only the first 8 hours all the time. Now i got this code:

public function notLoggedIn($whichtable, $whichrow, $link, $preference, $dag, $uur) { $this->newfunction = new functions;

    $getvalue = $this->newGet();
    $resultaat = DB_connect()->query("SELECT * FROM $whichtable WHERE $whichrow = '$preference'");

    $days = array("Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag"); // take all dagen op
    $loop = array();

    while($rij = $resultaat->fetch_assoc())
    {
            $loop[] = $rij;
    }

    foreach ($days as $currentDay) 
    {   
    echo "<table style='float:left; width:100%;'>";     
        echo "<th></th><th style='width:100%; left:0; background-color:#9a136e; color:#fff; font-size:20px;'>
        <div style='margin-auto;'>$currentDay</div></th>";  
        foreach($loop as $test) 
        {   
            $day = $test[$currentDay]; 
            $uren = $test['Uren'];

            $getkleur = explode(",", $day); 

                    echo "<tr>"; ?> <th style='width:20%; display:$getkleur[5]; border-right:1px dotted #000;'>
                    <? $this->newfunction->linkToHoure($uren)?></th><?
                    echo "<td style='border-bottom:1px solid #999; display:$getkleur[5]; width:100%; height:40px;'>".$getkleur[0]."
                    <a style='font-size:24px; margin-top:-7px; position:absolute; right:0;' href='#'>></a></td></tr>

                    <tr><td></td><td style='width:100%;'><b><a style='background-color:$getkleur[4]; color:#fff;' href=''>".$getkleur[3]."</b>
                    <b><a style='color:#906;' href=''>". $getkleur[2]."</b></a></td></tr>";             
        } // close foreach
    echo "</table>";
    } 
    }// close notloggedin function

Now it does display everthing on the same page , but like this:

 1. (Index of monday). Monday
    1. (Index of Tuesday). Tuesday
    1. (Index of Wednesday). Wednesday
    1. (Index of Thursday). Thursday
    1. (Index of Friday). Friday
    2. (Index of Monday). Monday
    2. (Index of Tuesday). Tuesday
    2. (Index of Wednesday). Wednesday
    2. (Index of Thursday). Thursday
    2. (Index of Friday). Friday

Till 8... Instead of the example above. But it should get seperated in hours & days.

I got no idea how to solve this. All help is appriciated..

  • 写回答

2条回答 默认 最新

  • dongyi6269 2013-05-26 18:16
    关注

    First try switching the while and foreach parts.'For each day' should come first, then loop through the table with the actual day selected.

    Formatting should be another part, but this ought to give you the desired 8 lines per day output.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)