簡體   English   中英

用查詢PHP的結果制作表格

[英]Making a table with result of a query php

我想在2個日期之間進行選擇,然后回顯此圖像中的結果 圖片

這是我的代碼,我想將其更新為只要有人可以幫助我,我將不勝感激。

碼:

<?php
$dataini = mysqli_real_escape_string($link, $_POST['field2']);
            $dataini = date('Y-m-d', strtotime(str_replace('-', '/', $dataini)));
            $datafim = mysqli_real_escape_string($link, $_POST['field3']);
            $datafim = date('Y-m-d', strtotime(str_replace('-', '/', $datafim)));
$query = mysqli_query($link, "SELECT * FROM conteudo where d_datapub between '$dataini' and '$datafim'");
                    $todos = mysqli_num_rows($query); 
                    echo $todos;
?>

HTML

 <html>
    <link rel="stylesheet" type="text/css" href="../css/pesquisa.css">
    <div class="well-searchbox">
        <form action="" class="form-horizontal" method="post" role="form">
            <div class="form-group">
                <label class="col-md-4 control-label">Portais</label>
<div class="form-group">
                    <label class="col-md-4 control-label">Data Inicio</label>
                    <div class="col-md-8">
                        <input type="text" readonly name="field2" id="field2" alt="Data de Nascimento" class="IP_calendar" title="Y/m/d" style="width:200px;" placeholder="Ano-Mes-Dia">
                </div>
                <div class="form-group">
                    <label class="col-md-4 control-label">Data Fim</label>
                    <div class="col-md-8">
                        <input type="text" readonly name="field3" id="field3" alt="Data de Nascimento" class="IP_calendar" title="Y/m/d" style="width:200px;" placeholder="Ano-Mes-Dia">
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-4 col-sm-5">
                        <button type="submit" name="contardata" class="btn btn-primary">Contar</button>
                    </div>
</html>

這是一個有關如何使用html table echo php結果的示例

<table>
    <thead>
        <th>Portal</th>
        <th>Results</th>
    </thead>
<tbody>
<?php
$dataini = mysqli_real_escape_string($link, $_POST['field2']);
        $dataini = date('Y-m-d', strtotime(str_replace('-', '/', $dataini)));
        $datafim = mysqli_real_escape_string($link, $_POST['field3']);
        $datafim = date('Y-m-d', strtotime(str_replace('-', '/', $datafim)));
$query = mysqli_query($link, "SELECT * FROM conteudo where d_datapub between '$dataini' and '$datafim'");
                $todos = mysqli_num_rows($query); 
                while ($row = mysqli_fetch_assoc($query)) {
                $portalname = $row['portalname'];//name of database table column with the portal name
                $portalresult = $row['portalresult'];

                echo "<tr>";
                echo "<td>" .$portalname"</td>";
                echo "<td>" .$portalresult"</td>";
                echo "</tr>";
?>
    </tbody>
</table>

暫無
暫無

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

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