drn5375 2019-04-25 22:14
浏览 40

如何在bootstrap 3表中显示这些php搜索结果

I would like to display the information in the database using php but need the table to be styled using bootstrap 3 and not the default html table tag. I need assistance to fix this challenge so that i can have a better understanding of how to display search results using php. Thanks

<?php
$connect = mysqli_connect("localhost", "root", "", "oas");
if ($connect) {

    $search = "";

    $query = "SELECT distinct(M.`s_id`) as `s_id`,
                     M.`s_mark`,
                     U.`s_name`
                     FROM `t_usermark` as M
                    JOIN `t_user_data` as U on M.s_id = U.s_id  WHERE `s_name` like '%$search%'";
    $result = mysqli_query($connect, $query);

    if ($result) {
        if (mysqli_num_rows($result) > 0) {
            echo "
                    <table>
                        <tr>
                            <th>ID</th>
                            <th>Name</th>
                            <th>Mark</th>
                        </tr>
                    ";
            while ($row = mysqli_fetch_array($result)) {
                $id = $row['s_id'];
                $mark = $row['s_mark'];
                $name = $row['s_name'];

                echo "
                            <tr>
                                <td>$id</td>
                                <td>$name</td>
                                <td>$mark</td>
                            </tr>
                        ";

                // echo "<p>$id</p><p>$mark</p><p>$name</p>";
            }

        } else {
            echo "No results";
        }

        echo "</table>";
    } else {
        echo mysqli_error($connect);
    }
} else {
    echo "Database connection failed";
}

?>
  • 写回答

2条回答 默认 最新

  • donglv6960 2019-04-25 23:13
    关注

    try this

        <!doctype html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <title>Search result  </title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    </head>
    <body>
    <?php
    $connect = mysqli_connect("localhost", "root", "", "oas");
    if ($connect) {
    
    $search = "";
    
    $query = "SELECT distinct(M.`s_id`) as `s_id`,
                         M.`s_mark`,
                         U.`s_name`
                         FROM `t_usermark` as M
                        JOIN `t_user_data` as U on M.s_id = U.s_id  WHERE `s_name` like '%$search%'";
    $result = mysqli_query($connect, $query);
    
    if ($result) {
        if (mysqli_num_rows($result) > 0) {
            echo "<table>
                            <tr>
                                <th>ID</th>
                                <th>Name</th>
                                <th>Mark</th>
                            </tr>
                        ";
            while ($row = mysqli_fetch_array($result)) {
                $id = $row['s_id'];
                $mark = $row['s_mark'];
                $name = $row['s_name'];
                    echo '<tr>
          <th scope="row">'.$id.'</th>
          <td>'.$name.'</td>
          <td>'.$mark.'</td>
        </tr>';
                }
    
                echo '
    </tbody>
    </table>';
            } else {
                echo "No results";
            }
    
            echo "</table>";
        } else {
            echo mysqli_error($connect);
        }
    } else {
        echo "Database connection failed";
    }
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端