我需要你的帮助..
我可以通过填写选择板作为选项的html表单来查看单个人的结果,并按卷号(123456)搜索以查看所有列...
以下php
<?php
// php code to search data in mysql database and set it in input text
if(isset($_POST['search']))
{
// id to search
$roll = $_POST['roll'];
$board = $_POST['board'];
//connect to the database
include('connect.php');
// mysql search query
$query = "SELECT `firstname`, `lastname`, `roll`, `city`, `board` FROM `result` WHERE `roll` = $roll and `board` = $board LIMIT 1";
$result = mysqli_query($connect, $query);
// if id exist
// show data in inputs
if(mysqli_num_rows($result) > 0)
{
echo "<table width='540' height='69'><thead><tr>
<th width='14%'><div align='center'>first name</div></th>
<th width='12%'><div align='center'>last name</div></th>
<th width='17%'><div align='center'>roll number</div></th>
<th width='14%'><div align='center'>city</div></th>
<th width='22%'><div align='center'>board</div></th>
</tr></thead>
<tfoot>
</tfoot>
<tbody>
<tr class='alt'>";
while ($row = mysqli_fetch_array($result))
{
echo "<td><div align='center'>" . $row['firstname'] . "</div></td>";
echo "<td><div align='center'>" . $row['lastname'] . "</div></td>";
echo "<td><div align='center'>" . $row['roll'] . "</div></td>";
echo "<td><div align='center'>" . $row['city'] . "</div></td>";
echo "<td><div align='center'>" . $row['board'] . "</div></td>";
}
echo "</tbody>";
echo "</table>";
}
mysqli_free_result($result);
mysqli_close($connect);
}
?>
现在我想要的是搜索随机卷号..
请查看表单图片
请在我的php中进行更改,以便我可以使用此表单..
随机结果应该是这样的
firstname lastname roll city board
name1 lname1 3456 - -
name2 lname2 8765 - -
name3 lname3 4567 - -
也是顺序的,例如在搜索中写入(从1001到1100)以查看100人的结果..
顺序结果应该是这样的
firstname lastname roll city board
name1 lname1 1001 - -
name2 lname2 1002 - -
name3 lname3 1003 - -
.............................................
name100 lname100 1100 - -
答案 0 :(得分:0)
您需要根据需要更改查询
$query = "SELECT `firstname`, `lastname`, `roll`, `city`, `board`
FROM `result` WHERE 1=1 ";
if(isset( $_POST['roll'])){ // Assuming this as single roll text
$query.=" AND `roll` = '$roll'";
}
if(isset($_POST['fromroll']) && isset($_POST['toroll'])){ // This as From and To
$fromroll=$_POST['fromroll'];
$toroll=$_POST['toroll'];
$query.=" AND roll between '$fromroll' AND '$toroll' ";
}
if(isset($_POST['multipleroll']))
{
$multipleroll=$_POST['multipleroll'];
$query.=" AND roll in ('$multipleroll') ";
}
$result = mysqli_query($connect, $query);