doudang4568 2013-11-08 11:30
浏览 25
已采纳

使用mysql ressources在循环内部循环

I'm trying to do some loops in loop using mysql but it seems that there not interpreted

it returns only the first result then nothing even If I have many records in my database, It should return everything

below is my code that display the results

while ($cr = mysql_fetch_assoc($result)):
    $i = 0;
    ++$i;
    ?>
    <div style="width:200px"  class="fif"><table style="width:100%">
        <tr class="fbgreybox">
        <td colspan="3" style="text-align: center;font-weight: bold">
            <img src="images/calendar_2.png"> Séance du : <?php echo date('d-m-Y', strtotime($cr['record'])); ?>
        </td>
        </tr>
        <?php
        $sql = "SELECT `exercise` FROM `workouts` WHERE `record` = '{$cr['record']}' AND `user`= {$_SESSION['userid']} GROUP BY `exercise`";
        $result = mysql_query($sql);
        while ($exo = mysql_fetch_assoc($result)) :
        ?>
            <tr class="fbinfobox">
            <td colspan="3" style="text-align: left">
                <img src="images/Sport-dumbbell.png"> ////<?php echo exerciseName($exo['exercise']); ?>
            </td>
            </tr>
            <tr>
            <td style="text-align: center;font-weight: bold">Séries</td>
            <td style="text-align: center;font-weight: bold">Reps</td>
            <td style="text-align: center;font-weight: bold">Poids</td>
            </tr>
        <?php
        $rqt = "SELECT `set_number`, `reps`, `weight` FROM `workouts` WHERE `exercise` = {$exo['exercise']} AND `record` = '{$cr['record']}' AND `user` = {$_SESSION['userid']} ORDER BY `set_number`";
        $result2 = mysql_query($rqt);
        while ($detail = mysql_fetch_assoc($result2)):
            ?>
            <tr>
            <td>
                Série ////<?php echo $detail['set_number']; ?>
            </td>
            <td>
                <?php echo $detail['reps']; ?>
            </td>
            <td>
                <?php echo $detail['weight']; ?>
            </td>
            </tr>
            <?php
        endwhile;
        endwhile;
        ?>
    </table>
    </div>
    <?php
endwhile;

there is not mistakes in the code so I really do not understand why it is not interpreted.

anykind of help will be much appreciated.

  • 写回答

2条回答 默认 最新

  • dqqlziv195281 2013-11-08 11:32
    关注

    You are using $result in both mysql_fetch_assoc() function. AVOID THAT.

    In inner loop you can use another variable:

    $sql = "SELECT `exercise` FROM `workouts` WHERE `record` = '{$cr['record']}' AND `user`= {$_SESSION['userid']} GROUP BY `exercise`";
    $workoutsResult = mysql_query($sql);
    while ($exo = mysql_fetch_assoc($workoutsResult )) :
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号