簡體   English   中英

從PHP中的SQL數據庫獲取數據以獲取表

[英]Get data from SQL Database in PHP for a table

編輯 :在PHP 7使用mysql_connect 解決了

我嘗試用數據庫中的最后一個條目創建一個表,所以我嘗試獲取我的最后5個數據並在表中重復它。

這是我的數據庫的結構:

CREATE TABLE `submitph` (
  `id` int(11) NOT NULL,
  `phrase` text NOT NULL,
  `mode` varchar(255) NOT NULL,
  `enable` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

和我的PHP代碼

<tbody>
                        <?php
                        mysql_connect("localhost", "root", "root");
                        mysql_select_db("jnj");
                            $retour = mysql_query('SELECT * FROM submitph ORDER BY id DESC LIMIT 0,5');
                            while ($donnees = mysql_fetch_array($retour))
                            {
                        ?>
                        <tr>
                          <td>
                            <?php echo stripslashes($donnees['id']); ?>
                          </td>
                          <td>
                            <?php 
                                 $phrase = nl2br(stripslashes($donnees['phrase']));
                                 echo $phrase;
                            ?>
                          </td>
                          <td>
                            <a href="">Approuver</a> / <a href="">Refuser</a>
                          </td>

                        </tr>
                        <?php
}    ?>

                      </tbody>

但我的表中沒有任何數據,我沒有任何php錯誤,不明白為什么。 我錯過了什么 ?

編輯1(我所有的桌子):

       <table class="table table-hover">
                      <thead class="">
                                <th>
                          ID
                        </th>
                        <th>
                          Phrase
                        </th>
                        <th>
                          Status
                        </th>

                      </thead>
                      <tbody>
                                            <?php
                        mysql_connect("localhost", "root", "root");
                        mysql_select_db("jnj");
                            $retour = mysql_query('SELECT * FROM submitph ORDER BY id DESC LIMIT 0,5');
                            while ($donnees = mysql_fetch_array($retour))
                            {
                        ?>
                        <tr>
                          <td>
                            <?php echo stripslashes($donnees['id']); ?>
                          </td>
                          <td>
                            <?php 
                                 $phrase = nl2br(stripslashes($donnees['phrase']));
                                 echo $phrase;
                            ?>
                          </td>
                          <td>
                            <a href="">Approuver</a> / <a href="">Refuser</a>
                          </td>

                        </tr>
                        <?php
} 
?>

                      </tbody>
                    </table>

編輯2:SQL數據

INSERT INTO `submitph` (`id`, `phrase`, `mode`, `enable`) VALUES
(3, 'Test1', 'Hard', 0),
(5, 'Test2', 'Soft', 0),
(6, 'Test3', 'Hard', 0);

SQL數據

您沒有將$ connection變量傳遞給mysql_query();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM