dongwo5110 2013-06-28 04:06
浏览 46
已采纳

使用php和mysql在页面上添加多个do语句

Ok so I didn't see anything like this in the previous postings so if if has been covered before sorry for the repost.

I am trying to put a second do..while statement in the same page but when I do this it seems to drag down the page. it loads fine if I have only one statement in there but the minute I put in a second one it takes forever to load the page. I have a need of adding a total of 9 do..while statements which will most likely kill the page at this point. I'm not sure why it would be doing this any ideas?

The code I'm using is as follows

<p><?php
    do {
    $row_myContacts = mysql_fetch_assoc($myContacts);
    if ($row_myContacts['staffID'] != "81"){                                
    }
    else {
     echo $row_myContacts['firstName'] . " " . $row_myContacts['lastName'];?></p>
                  <p class="staff_title_national"><?php echo $row_nmyContacts['titleName'];?></p>
                  <br />
                  <li><?php echo $row_myContacts['address1'] 
. " " . $row_myContacts['address2'] ;?></li>
                  <li><?php echo $row_myContacts['cityName'] 
. ", " . $row_myContacts['state_abreviation'] . " " 
. $row_myContacts['zipCode'];?></li>
                  <br />
                  <li>Office: <?php echo format_phone($new_office_phone); ?></li>
                  <li>Fax: <?php echo format_phone($new_fax_phone); ?></li>
                  <br />
                  <br />
                  <li>E-Mail: 
<a href="<?php echo $row_myContacts['email'];?>"><?php echo $row_myContacts['email'];?></a></li>
                  <br />
           <?php }
    } while ($row_myContacts['staffID'] != '81')?>

I have tried testing it so that the staffID is == to the number i need, but it doesn't output anything. I think it should be that way but for some reason it doesn't work. and yes I moved the stuff in that variation so that the else was empty and the if had the information in it.

The page holds 4 sections of contacts under section 1 there is one section with 2 names (same address info) section 2 has 3 names different info, sections 3 and 4 have 2 each with different info. I even created 2 new tables in my database that reference the 4 sections if that helps. I do know my sql statement is correct it pulls all 9 contacts with their corresponding information.

/edit below/

so I also tried the code this way. and I do get it to load the first one but when I add a section for loop it shows nothing. I think it is because I am telling the loop to access the database at the same point that it left off so it isn't starting over on the loop.

<?php
            for ($x=$totalRows_myContacts; $x>=1; $x--){

                if ($row_myContacts['staffID'] == '81') {
                echo $row_myContacts['firstName'] . " " . $row_myContacts['lastName'];?></p>
                  <p class="staff_title"><?php echo $row_myContacts['titleName'];?></p>
                  <br />
                  <li><?php echo $row_myContacts['address1'] . " " . $row_myContacts['address2'] ;?></li>
                  <li><?php echo $row_myContacts['cityName'] . ", " . $row_myContacts['state_abreviation'] . " " . $row_myContacts['zipCode'];?></li>
                  <br />
                  <li>Office: <?php echo format_phone($new_office_phone); ?></li>
                  <li>Fax: <?php echo format_phone($new_fax_phone); ?></li>
                  <br />
                  <br />
                  <li class="emailTealGrey">E-Mail: <a href="<?php echo $row_myContacts['email'];?>"><?php echo $row_myContacts['email'];?></a></li>
                  <br />   

            <?php }$row_myContacts = mysql_fetch_assoc($Contacts);  
            }?>

so not sure how to tell the database to access itself again and start the query from the top I guess is what I need to do. any ideas how to tell it to do that?

  • 写回答

1条回答 默认 最新

  • dougao7801 2013-06-28 04:20
    关注

    What happens if there is no row for staffID=81 change code to something like this,

    .....
    do {
        $row_myContacts = mysql_fetch_assoc($myContacts);
        if ($row_myContacts == false){
            break;
        }
    .....
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度