页面无法正确显示

时间:2013-05-30 20:13:23

标签: php mysql loops while-loop

我有以下代码。它运行良好,直到最后一点。在// Close Main while loop评论之后,似乎只是关闭并停止显示页面的其余部分,我似乎无法理解为什么。

    <?php
//show everything
error_reporting(E_ALL);

//using php.ini and ini_set()
ini_set('error_reporting', E_ALL);

require_once('header.tpl');

$my_id = '19';
mysql_connect("localhost","*********","*********") or die (mysql_error());
    mysql_select_db("*********") or die (mysql_error());
    ?>
    <!-- Navbar/popouts/notloggedin end -->
    <script language="javascript" type="text/javascript">
    function toggleChecks(field) {
        if (document.myform.toggleAll.checked == true){
              for (i = 0; i < field.length; i++) {
                  field[i].checked = true;
              }
        } else {
              for (i = 0; i < field.length; i++) {
                  field[i].checked = false;
              }     
        }

    }
    $(document).ready(function() { 
    $(".toggle").click(function () { 
      if ($(this).next().is(":hidden")) {
        $(".hiddenDiv").hide();
        $(this).next().slideDown("fast"); 
      } else { 
        $(this).next().hide(); 
      } 
    }); 
    });
    function markAsRead(msgID) {
        $.post("markAsRead.php",{ messageid:msgID, ownerid:<?php echo $my_id; ?> } ,function(data) {
            $('#subj_line_'+msgID).addClass('msgRead');
           // alert(data); // This line was just for testing returned data from the PHP file, it is not required for marking messages as read
       });
    }
    </script>
    <style type="text/css">
    .hiddenDiv {
        display:none
    }
    #pmFormProcessGif {
        display:none
    }
    .msgDefault {
        font-weight:bold;
    }
    .msgRead {
        font-weight:100;
        color:#666;
    }
    </style>

    <div class="container">
    <div class="row"> 
      <!-- /Welcome text -->
      <div class="span12">
        <div class="navbar navbar-inverse" style="position: static;">
          <div class="navbar-inner">
            <div class="container"><a class="btn btn-navbar" data-toggle="collapse" data-target=".navbar-inverse-collapse"><span class="icon-bar"></span> <span class="icon-bar"></span><span class="icon-bar"></span></a>
              <div class="nav-collapse collapse navbar-inverse-collapse">
                <ul class="nav">
                  <li><a href="#">Inbox</a></li>
                  <li><a href="#">Sent</a></li>
                  <li><a href="#">Deleted</a></li>
                  <form class="navbar-search pull-left" action="">
                    <input type="text" id="inbox_search" class="search-query span2" placeholder="Search Emails" />
                  </form>
                </ul>
                <ul class="nav pull-right">
                  <li><a href="#"><i class="icon-file icon-white"></i></a></li>
                  <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="icon-wrench icon-white"></i></a>
                    <ul class="dropdown-menu">
                      <li><a href="#">Create New Folder</a></li>
                      <li><a href="#">Message Templates</a></li>
                    </ul>
                  </li>
                </ul>
              </div>
            </div>
          </div>
          <!-- /navbar-inner --> 
        </div>
      </div>
    </div>
    <div class="row">
      <div class="span12">
        <table class="fulltable">
          <tr>
            <td class="fulltable_topbar" colspan="2"></td>
          </tr>
          <tr>
            <td class="fulltable_title"><div></div></td>
          </tr>
          <tr>
            <td class="fulltable_content" style="padding-top:10px"><div> 
                <!-- START THE PM FORM AND DISPLAY LIST -->
                <form name="myform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
                  <table width="94%" border="0" align="center" cellpadding="4">
                    <tr>
                      <td width="3%" align="right" valign="bottom"><img src="images/crookedArrow.png" width="16" height="17" alt="Develop PHP Private Messages" /></td>
                      <td width="97%" valign="top"><input type="submit" name="deleteBtn" class="btn btn-small btn-invese" id="deleteBtn" value="Delete" />
                        <span id="jsbox" style="display:none"></span></td>
                    </tr>
                  </table>
                  <table width="96%" border="0" align="center" cellpadding="4" style="background-image:url(images/headerStrip.jpg); background-repeat:repeat-x; border: #999 1px solid;">
                    <tr>
                      <td width="4%" valign="top"><input name="toggleAll" id="toggleAll" type="checkbox" onclick="toggleChecks(document.myform.cb)" /></td>
                      <td width="20%" valign="top">From</td>
                      <td width="58%" valign="top"><span class="style2">Subject</span></td>
                      <td width="18%" valign="top">Date</td>
                    </tr>
                  </table>
                  <?php
    ///////////End take away///////////////////////
    // SQL to gather their entire PM list
    $sql = mysql_query("SELECT * FROM private_messages WHERE to_id='$my_id' AND recipientDelete='0' ORDER BY id DESC LIMIT 100");

    while($row = mysql_fetch_array($sql) **or die(mysql_error())**){ <error was the or die!

        $date = strftime("%b %d, %Y",strtotime($row['time_sent']));
        if($row['opened'] == "0"){
                $textWeight = 'msgDefault';
        } else {
                $textWeight = 'msgRead';
        }
        $fr_id = $row['from_id'];    
        // SQL - Collect username for sender inside loop
        $ret = mysql_query("SELECT id, username FROM members WHERE id='$fr_id' LIMIT 1");
        while($raw = mysql_fetch_array($ret)){ $Sid = $raw['id']; $Sname = $raw['username']; }

    ?>
                  <table width="96%" border="0" align="center" cellpadding="4">
                    <tr>
                      <td width="4%" valign="top"><input type="checkbox" name="cb<?php echo $row['id']; ?>" id="cb" value="<?php echo $row['id']; ?>" /></td>
                      <td width="20%" valign="top"><a href="<?php echo $Sname; ?>"><?php echo $Sname; ?></a></td>
                      <td width="58%" valign="top"><span class="toggle" style="padding:3px;"> <a class="<?php echo $textWeight; ?>" id="subj_line_<?php echo $row['id']; ?>" style="cursor:pointer;" onclick="markAsRead(<?php echo $row['id']; ?>)"><?php echo stripslashes($row['subject']); ?></a> </span>
                        <div class="hiddenDiv"> <br />
                          <?php echo stripslashes(wordwrap(nl2br($row['message']), 54, "\n", true)); ?> <br />
                          <br />
                          <a href="javascript:toggleReplyBox('<?php echo stripslashes($row['subject']); ?>','<?php //echo $my_uname; ?>','<?php echo $my_id; ?>','<?php echo $Sname; ?>','<?php echo $fr_id; ?>','<?php //echo $thisRandNum; ?>')">REPLY</a><br />
                        </div></td>
                      <td width="18%" valign="top"><span style="font-size:10px;"><?php echo $date; ?></span></td>
                    </tr>
                  </table>
                  <hr style="margin-left:20px; margin-right:20px;" />
                  <?php
    }// Close Main while loop
    ?>
                </form>
                <!-- END THE PM FORM AND DISPLAY LIST --> </div></td>
          </tr>
          <tr>
            <td class="fulltable_bottom" colspan="2"></td>
          </tr>
        </table>
      </div>
    </div>
    </body>
    </br>
    </br>
    <?php require_once('footer.tpl'); ?>

4 个答案:

答案 0 :(得分:0)

为什么;之后}(请删除)

   } // Close Main while loop

同样的错误:

 if($row['opened'] == "0"){
            $textWeight = 'msgDefault';
    } else {
            $textWeight = 'msgRead';
    };

答案 1 :(得分:0)

你在两个闭环花括号;

之后添加了一些分号}(不需要)
};   
$fr_id = $row['from_id'];   

应该是

}   
$fr_id = $row['from_id'];   

};// Close Main while loop

必须

}// Close Main while loop

答案 2 :(得分:0)

只是一个抬头。虽然您的错误似乎已经彻底解决了,但我建议您使用可以检测这些类型问题的IDE。这样你就不会在职业生涯的其余部分寻找分号。这是Aptana的链接,它是一个代码编辑器,有很多内置的错误检测功能。基本上会在包含基本错误的行下弹出红线,例如缺少;)。祝你好运。

http://www.aptana.com/

答案 3 :(得分:0)

 $sql = mysql_query("SELECT * FROM private_messages WHERE to_id='$my_id' AND recipientDelete='0' ORDER BY id DESC LIMIT 100");

while($row = mysql_fetch_array($sql) **or die(mysql_error())**){ <error was the or die!

错误在上面:)