我的数据库中没有显示任何内容

时间:2014-04-23 16:52:46

标签: php mysql

我试图从我的数据库中显示一些结果,但没有显示任何内容。请帮帮我。

      <?php
                include_once("connect.php");
                //query the database
                $query = mysql_query("SELECT * FROM evaluation ORDER BY Matricule DESC") or die($myQuery."<br/><br/>".mysql_error());;
                //fetch the results / convert results into an array

                while($rows = mysql_fetch_array($query)):

                    $id_Matiere = $row['id_Matiere'];
                    $Td = $row['Td'];
                    $Tp = $row['Tp'];
                    $Exam = $row['Exam'];
                    echo $id_Matiere .$Td .$Tp .$Exam;
                endwhile;
            ?>

-----------note-off.php--------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN" dir="ltr">
<head >
<title>Département Math-Info | Note Tab</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="imagetoolbar" content="no" />
<link rel="stylesheet" href="styles/layout.css" type="text/css" />
<!-- 3 Column Stylesheet Added To The Page And Not To The Layout.css -->
<link rel="stylesheet" href="styles/3_column.css" type="text/css" />
</head>
<body id="top">
<div class="wrapper row1">
  <div id="header" class="clear">
    <div class="fl_left">
      <h1><a href="index.html">Département Math-Info </a></h1>
      <p>Just pour vous</p>
    </div>
    <form action="#" method="post" id="login">
      <fieldset>
      <h6>Ensignant Login</h6>
        <legend>Ensignant Login</legend>
        <input type="password" />
        <input type="text" />
        <div id="forgot">Need <a href="#">Help ?</a> or <a href="#">Forgot Your Details ?</a></div>
        <input type="image" src="images/sign_in.gif" id="signin" alt="Sign In" />
      </fieldset>
    </form>
  </div>
</div>
<!-- ####################################################################################################### -->
<div class="wrapper row2">
  <div id="topnav">
    <ul>
      <li><a href="index.html">Homepage</a></li>
      <li><a href="contact-us.html">CONTACT US</a></li>
      <li><a href="nouveauté.html">NOUVEAUTé</a></li>

      <li class="active"><a href="note-tab.html">Note Tab</a></li>
      <li class="last"><a href="gallery.html">Gallery</a></li>
    </ul>
    <div  class="clear"></div>
  </div>
</div>
<!-- ####################################################################################################### -->
<div class="wrapper row4">
  <div id="container" class="clear">
    <!-- ####################################################################################################### -->
    <div id="left_column">
      <div class="holder">
        <h2 class="title">Quick Links</h2>
        <ul class="nostart">
          <li><a href="contact-us.html">Contact Us</a></li>
            <li><a href="#">Nouveauté</a></li>
            <li><a href="#">Spéciality</a></li>
            <li><a href="#">Math &amp; Informatique</a></li>
            <li><a href="#">2em Math</a></li>
            <li><a href="#">3em Math</a></li>
            <li><a href="#">2em Informatique</a></li>
            <li><a href="#">3em Informatique</a></li>
            <li><a href="#">Student Login</a></li>
            <li><a href="#">Ensignant Login</a></li>
            <li><a href="#">Online Courses</a></li>
            <li><a href="#">Gallery</a></li>
        </ul>
      </div>
      <div class="holder">
        <h2 class="title">Lorem ipsum dolor</h2>
        <div class="imgholder"><img src="images/demo/190x90.gif" alt="" /></div>
        <div class="imgholder last"><img src="images/demo/190x90.gif" alt="" /></div>
      </div>
    </div>
    <!-- ############ -->
    <div id="content">
        <p>You Must login to see this Content : <p>

      <table summary="Summary Here" cellpadding="0" cellspacing="0">
        <thead>
          <tr>
            <th>Header 1</th>
            <th>Header 2</th>
            <th>Header 3</th>
            <th>Header 4</th>
          </tr>
        </thead>
        <tbody>
          <tr class="light">
            <?php
                require("connect.php");
                //query the database
                $query = mysql_query("SELECT * FROM evaluation") or die($myQuery."<br/><br/>".mysql_error());
                //fetch the results / convert results into an array

                while($rows = mysql_fetch_array($query)):

                    $id_Matiere = $rows['id_Matiere'];
                    $Td = $rows['Td'];
                    $Tp = $rows['Tp'];
                    $Exam = $rows['Exam'];
                    echo "$id_Matiere $Td $Tp $Exam";
                endwhile;
            ?>
          </tr>

        </tbody>
      </table>

    </div>
    <!-- ############ -->
    <div id="right_column">
      <div class="holder">
        <h2 class="title">Definition Of The Note-Tab </h2>
        <p>This Tab is used to Display Notes of TD TP & Exam .</p>

        <p>To Be Able to see what in this tab <a href="note-off.html">NOTE-TAB</a> you must login through the login area Above ,if u are
        Ensignant you have to use your Email and Password to log-in ,or if you're a Student u can use your Matricule Thanks. </p>
        <p class="readmore"><a href="#">Continue Reading &raquo;</a></p>
      </div>
      <div class="holder">
        <h2 class="title">Publicity</h2>
        <div class="imgholder"><img src="images/demo/240x90.gif" alt="" /></div>
        <div class="imgholder"><img src="images/demo/240x90.gif" alt="" /></div>
        <div class="imgholder last"><img src="images/demo/240x90.gif" alt="" /></div>
      </div>
    </div>
    <!-- ####################################################################################################### -->
  </div>
</div>
<!-- ####################################################################################################### -->
<div class="wrapper row5">
  <div id="footer" class="clear">
    <!-- ####################################################################################################### -->
    <div class="foot_contact">
      <h2>University Name Here</h2>
      <address>
      Address Line 1<br />
      Address Line 2<br />
      Town/City<br />
      Postcode/Zip
      </address>
      <ul>
        <li><strong>Tel:</strong> xxxxx xxxxxxxxxx</li>
        <li><strong>Fax:</strong> xxxxx xxxxxxxxxx</li>
        <li class="last"><strong>Email:</strong> <a href="#">contact@mydomain.com</a></li>
      </ul>
    </div>
    <div class="footbox">
      <h2>Administration</h2>
      <ul>
        <li><a href="#">Disclaimer</a></li>
        <li><a href="#">Accessibility</a></li>
        <li><a href="#">Freedom of Information</a></li>
        <li><a href="#">Website Privacy</a></li>
        <li><a href="#">Press Release Information</a></li>
        <li><a href="#">Annual Report</a></li>
        <li><a href="#">Financial Statements</a></li>
        <li><a href="#">Job Vacancies</a></li>
        <li class="last"><a href="#">Semester Dates</a></li>
      </ul>
    </div>
    <div class="footbox">
      <h2>Link Block 2</h2>
      <ul>
        <li><a href="#">Schools and Colleges</a></li>
        <li><a href="#">Student Activities</a></li>
        <li><a href="#">Student Affairs</a></li>
        <li><a href="#">Student Development</a></li>
        <li><a href="#">Student Financial Services</a></li>
        <li><a href="#">Student Group Directory</a></li>
        <li><a href="#">Student Life</a></li>
        <li><a href="#">International Students</a></li>
        <li class="last"><a href="#">Global Learning</a></li>
      </ul>
    </div>
    <div class="footbox last">
      <h2>Link Block 3</h2>
      <ul>
        <li><a href="#">Academic Advisory</a></li>
        <li><a href="#">Academic Assistance</a></li>
        <li><a href="#">Academic Calendars</a></li>
        <li><a href="#">Academics Office</a></li>
        <li><a href="#">Administration</a></li>
        <li><a href="#">Adult Learners</a></li>
        <li><a href="#">Alumni Chapters</a></li>
        <li><a href="#">Alumni Events</a></li>
        <li class="last"><a href="#">Residential Colleges</a></li>
      </ul>
    </div>
    <!-- ####################################################################################################### -->
  </div>
</div>
<!-- ####################################################################################################### -->
<div class="wrapper">
  <div id="copyright" class="clear">
    <p class="fl_left">Copyright &copy; 2013 - All Rights Reserved - <a href="#">Domain Name</a></p>
    <p class="fl_right">Template by <a href="http://www.os-templates.com/" title="Free Website Templates">OS Templates</a></p>
  </div>
</div>
</body>
</html>

我试图在我的网站上输出数据库的结果,但它没有按照我想要的方式显示(在表格和css desing中)请做什么

和我引用的这部分代码:

 <div id="content">
            <p>You Must login to see this Content : <p>

          <table summary="Summary Here" cellpadding="0" cellspacing="0">
            <thead>
              <tr>
                <th>Header 1</th>
                <th>Header 2</th>
                <th>Header 3</th>
                <th>Header 4</th>
              </tr>
            </thead>
            <tbody>
              <tr class="light">
                <?php
                    require("connect.php");
                    //query the database
                    $query = mysql_query("SELECT * FROM evaluation") or die($myQuery."<br/><br/>".mysql_error());
                    //fetch the results / convert results into an array

                    while($rows = mysql_fetch_array($query)):

                        $id_Matiere = $rows['id_Matiere'];
                        $Td = $rows['Td'];
                        $Tp = $rows['Tp'];
                        $Exam = $rows['Exam'];
                        echo "$id_Matiere $Td $Tp $Exam";
                    endwhile;
                ?>
              </tr>

            </tbody>
          </table>

        </div>

4 个答案:

答案 0 :(得分:1)

错字 -

$query = mysql_query("SELECT * FROM evaluation ORDER BY Matricule DESC") 
         or die($myQuery."<br/><br/>".mysql_error());;
                                                     ^====== extra semicolon

同时更改此内容($row$rows) -

while($rows = mysql_fetch_array($query)):

   $id_Matiere = $rows['id_Matiere'];
   $Td = $rows['Td'];
   $Tp = $rows['Tp'];
   $Exam = $rows['Exam'];
   echo $id_Matiere .$Td .$Tp .$Exam;

endwhile;


解决下一个问题:

<table summary="Summary Here" cellpadding="0" cellspacing="0">
<thead>
<tr>
   <th>Header 1</th>
   <th>Header 2</th>
   <th>Header 3</th>
   <th>Header 4</th>
</tr>
</thead>

<tbody>

<?php
require("connect.php");
//query the database
$query = mysql_query("SELECT * FROM evaluation") or die($myQuery."<br/> <br/>".mysql_error());
//fetch the results / convert results into an array

while($rows = mysql_fetch_array($query)):

    echo "<tr class='light'>";
    echo "<td>".$rows['id_Matiere']."</td>";
    echo "<td>".$rows['Td']."</td>";
    echo "<td>".$rows['Tp']."</td>";
    echo "<td>".$rows['Exam']."</td>";
    echo "</tr>";

endwhile;

?>

</tbody>
</table>

答案 1 :(得分:0)

您正在引用“行”,并且在循环中您已将变量命名为“rows”。

答案 2 :(得分:0)

试试这个:

 <?php
            include_once("connect.php");
            //query the database
            $query = mysql_query("SELECT * FROM evaluation ORDER BY Matricule DESC") or die($myQuery."<br/><br/>".mysql_error());;
            //fetch the results / convert results into an array

            while($row = mysql_fetch_array($query)):

                $id_Matiere = $row['id_Matiere'];
                $Td = $row['Td'];
                $Tp = $row['Tp'];
                $Exam = $row['Exam'];
                echo $id_Matiere .$Td .$Tp .$Exam;
            endwhile;
        ?>

答案 3 :(得分:0)

我注意到的一件事是你正在使用$ rows和$ row ......这似乎是一个错字。

这告诉我你可能没有为测试启用所有错误报告。如果所有错误都已启用,您可能会收到有关拼写错误的通知。 ;)您应该考虑这样做,然后如果修复拼写错误无法解决您的问题,则报告结果。


启用所有错误以进行开发

// Add this to *the very top* of your test script

error_all();


// Add this to your functions file

function error_all ()
{
    // Guaranteed to show all error levels in all versions
    error_reporting(-1);

    // Guaranteed to show everything on screen
    ini_set('display_errors', 1);

    // Show errors that occur during PHP's startup sequence
    ini_set('display_startup_errors', 1);
}


更新

关于您的问题更新和评论......

目前还不清楚您是否仍有数据问题(没有数据全部)或只是显示问题(数据,但没有显示您喜欢的方式)。我认为后者......在这种情况下它可能应该是一个单独的问题。总之...

如果您仍然没有从数据库中获取数据到屏幕......

很高兴帮助......一旦启用了所有错误并报告回来。 ;)否则,它真的可以是任何东西,每个人都是盲目的。看到错误或缺乏错误可能很容易解决您的问题,或者至少可以解决大部分问题。确保将error_all()放在测试脚本中的其他任何位置之前。

如果您要从数据库中获取数据到屏幕上,但它根本不显示您想要的内容......

看起来您正试图将几行字段回显到单个<tr>标记的中间。非常确定您希望所有字段中的<tr></tr>标记 ,并且每个字段周围都有<td></td> ...在这种情况下,您的CSS应该开始正常工作。

如果这些都不能解决您的问题......

回复或更新您的问题,明确清楚解决哪些问题以及您仍然遇到的问题。在尝试获得帮助时,这是一项重要的技能。