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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?