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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么