dongrendang6566 2017-12-11 04:44
浏览 17
已采纳

默认情况下,在php中不填充任何数据

Table_sup           |
+-------------------+
| supid=>int        |                
| scompany=>varchar | 
| sstate=>varchar   | 
| scity=>varchar    | 
| scat=>varchar     | 

PHP Code

<?php
    include "db_connect.php";  // including configuration file
?>
     <form name="frmdropdown" method="post" action="sample.php">
     <center>
            <h2 align="center">Select State</h2>
            <strong> Select State : </strong> 
     <select name="getData"> 
            <option value=""> -----------ALL----------- </option>
     <?php
            $dd_res=mysqli_query($con,"Select DISTINCT sstate from sup");   
                while($r=mysqli_fetch_row($dd_res))
                    { echo "<option value='$r[0]'> $r[0] </option>";}
     ?>
    </select>
    <input type="submit" name="Select" value="Select"/> 
    <br><hr>
    <table id="exampleL" class="display table table-striped table-bordered dt-responsive nowrap" cellpadding="1" cellspacing="1" width="" style="font-size:small;">
         <thead>
              <tr>
                   <th style=" background-color:lightblue">Company</th>
                   <th style=" background-color:lightgreen">City</th>
                   <th style=" background-color:lightgreen">State</th>
                   <th style=" background-color:lightgreen">Category</th>
              </tr>
        </thead>
        <tbody>
    <?php
        if($_SERVER['REQUEST_METHOD'] == "POST")
    {
         $des=$_POST["getData"]; 
         if($des=="")  // if ALL is selected in Dropdown box
         { 
             $res=mysqli_query($con,"Select * from sup");
         }
         else
         { 
             $res=mysqli_query($con,"Select * from sup where sstate='".$des."'");
         }
            //echo "<tr><td colspan='5'></td></tr>";
         while($row3=mysqli_fetch_array($res)){
         ?>
               <tr>
                    <td><?php echo $row3['scompany'];?></td>
                    <td><?php echo $row3['scity'];?></td>
                    <td><?php echo $row3['sstate'];?></td>
                    <td><?php echo $row3['scat'];?></td>
               </tr>                     
        <?php
            }
                }
        ?>
        </tbody>
        </table>
        </center>
        </form>

By Default there is no data populated in the table. When I press "select", then all data populate in the table.

What I want: by default, the table populated all data

I have a default table image after running the code.If required I can upload the image

  • 写回答

1条回答 默认 最新

  • dqq46733 2017-12-11 04:58
    关注
    <?php
        include "db_connect.php";  // including configuration file
    ?>
    <form name="frmdropdown" method="post" action="sample.php">
    <center>
            <h2 align="center">Select State</h2>
            <strong> Select State : </strong>
    <select name="getData">
            <option value=""> -----------ALL----------- </option>
    <?php
            $dd_res=mysqli_query($con,"Select DISTINCT sstate from sup");   
                while($r=mysqli_fetch_row($dd_res))
                    { echo "<option value='$r[0]'> $r[0] </option>";}
    ?>
    </select>
    <input type="submit" name="Select" value="Select"/> 
    <br><hr>
    <table id="exampleL" class="display table table-striped table-bordered dt-responsive nowrap" cellpadding="1" cellspacing="1" width="" style="font-size:small;">
         <thead>
              <tr>
                   <th style=" background-color:lightblue">Company</th>
                   <th style=" background-color:lightgreen">City</th>
                   <th style=" background-color:lightgreen">State</th>
                   <th style=" background-color:lightgreen">Category</th>
              </tr>
        </thead>
        <tbody>
    <?php
        $res=mysqli_query($con,"Select * from sup");
    
        // If select was clicked, then only where condition applies, and so $res will be replaced.
        if(isset($_POST['getData'] ) || !empty($des))
        {
            $des=$_POST["getData"]; 
            $res = mysqli_query($con,"Select * from sup where sstate='".$des."'");         
        }
            //echo "<tr><td colspan='5'></td></tr>";
        while($row3=mysqli_fetch_array($res)){
        ?>
               <tr>
                    <td><?php echo $row3['scompany'];?></td>
                    <td><?php echo $row3['scity'];?></td>
                    <td><?php echo $row3['sstate'];?></td>
                    <td><?php echo $row3['scat'];?></td>
               </tr>
        <?php } ?>
        </tbody>
        </table>
        </center>
        </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决