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