第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在網(wǎng)頁(yè)上的HTML表格中顯示MySQL數(shù)據(jù)庫(kù)表中的值

在網(wǎng)頁(yè)上的HTML表格中顯示MySQL數(shù)據(jù)庫(kù)表中的值

楊__羊羊 2019-07-30 11:38:27
在網(wǎng)頁(yè)上的HTML表格中顯示MySQL數(shù)據(jù)庫(kù)表中的值我想從數(shù)據(jù)庫(kù)表中檢索值并在頁(yè)面的html表中顯示它們。我已經(jīng)搜索了這個(gè),但我找不到答案,雖然這肯定是容易的(這應(yīng)該是數(shù)據(jù)庫(kù)的基礎(chǔ)知識(shí))。我想我搜索過(guò)的詞語(yǔ)具有誤導(dǎo)性。數(shù)據(jù)庫(kù)表名稱是票證,它現(xiàn)在有6個(gè)字段(submission_id,formID,IP,名稱,電子郵件和消息),但應(yīng)該有另一個(gè)名為ticket_number的字段。如何讓它在html表中顯示db中的所有值,如下所示:<table border="1">   <tr>     <th>Submission ID</th>     <th>Form ID</th>     <th>IP</th>     <th>Name</th>     <th>E-mail</th>     <th>Message</th>   </tr>   <tr>     <td>123456789</td>     <td>12345</td>     <td>123.555.789</td>     <td>John Johnny</td>     <td>johnny@example.com</td>     <td>This is the message John sent you</td>   </tr></table>然后是“約翰”之下的所有其他值。
查看完整描述

3 回答

?
POPMUISE

TA貢獻(xiàn)1765條經(jīng)驗(yàn) 獲得超5個(gè)贊

試試這個(gè):(完全動(dòng)態(tài)...)

<?php
$host    = "localhost";$user    = "username_here";$pass    = "password_here";$db_name = "database_name_here";//create connection$connection = mysqli_connect($host, $user, $pass, $db_name);//test if connection failedif(mysqli_connect_errno()){
    die("connection failed: "
        . mysqli_connect_error()
        . " (" . mysqli_connect_errno()
        . ")");}//get results from database$result = mysqli_query($connection,"SELECT * FROM products");$all_property = array();  //declare an array for saving property//showing propertyecho '<table class="data-table">
        <tr class="data-heading">';  //initialize table tagwhile ($property = mysqli_fetch_field($result)) {
    echo '<td>' . $property->name . '</td>';  //get field name for header
    array_push($all_property, $property->name);  //save those to array}echo '</tr>'; //end tr tag//showing all datawhile ($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    foreach ($all_property as $item) {
        echo '<td>' . $row[$item] . '</td>'; //get items using property value
    }
    echo '</tr>';}echo "</table>";?>


查看完整回答
反對(duì) 回復(fù) 2019-07-30
?
當(dāng)年話下

TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊

首先,連接到數(shù)據(jù)庫(kù):

$conn=mysql_connect("hostname","username","password");mysql_select_db("databasename",$conn);

您可以使用它來(lái)顯示單個(gè)記錄:

例如,如果URL是/index.php?sequence=123,則下面的代碼將從表中選擇,其中sequence = 123

<?php
$sql="SELECT * from table where sequence = '".$_GET["sequence"]."' ";$rs=mysql_query($sql,$conn) or die(mysql_error());$result=mysql_fetch_array($rs);echo '<table>
<tr>
<td>Forename</td>
<td>Surname</td>
</tr>
<tr>
<td>'.$result["forename"].'</td>
<td>'.$result["surname"].'</td>
</tr>
</table>';?>

或者,如果要列出與表中的條件匹配的所有值:

<?php
echo '<table>
<tr>
<td>Forename</td>
<td>Surname</td>
</tr>';$sql="SELECT * from table where sequence = '".$_GET["sequence"]."' ";$rs=mysql_query($sql,$conn) or die(mysql_error());while($result=mysql_fetch_array($rs)){echo '<tr>
<td>'.$result["forename"].'</td>
<td>'.$result["surname"].'</td>
</tr>';}echo '</table>';?>


查看完整回答
反對(duì) 回復(fù) 2019-07-30
  • 3 回答
  • 0 關(guān)注
  • 4744 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)