我如何编码搜索页面,结果将以表格形式显示在同一页面中 [英] How I can code a search page and the result will be displayed in the same page in a table form

查看:70
本文介绍了我如何编码搜索页面,结果将以表格形式显示在同一页面中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的代码是一个搜索代码,在文本框下面有3个单选按钮选项,学生表是第一个按索引号搜索的单选按钮,第二个是第一个名称,第三个是通过姓。

i想要一旦我在文本框中键入搜索值,然后单击三个单选按钮选项之一,然后单击搜索按钮进行搜索并将其显示在表格中的搜索表单下

i搜索了这段代码并且不明白如果有人知道代码将如何帮助我的话应该怎么做。



我尝试了什么:



the code i want is a search code with 3 radio button option under the text box form the student table the first radio button to search by the index number, the second by the first name , and the third is to search by the last name.
i want once i type the search value inside the text box and then click on one of the three radio button option and then click on the search button for the search and displayed it under the search form in a table
i searched for this code and did't understand how should do it please if someone know how the code will be help me in it.

What I have tried:

<?php


$con= mysqli_connect('localhost' , 'root' , '' , 'gb8');
if (mysqli_connect_error()) {
	die ("Connection failed" . mysqli_connect_error());
}

$index_checked='unchecked';
$fname_checked='unchecked';
$lname_checked='unchecked';

	

	
	if(isset($_POST['submit']))
	{
	if(isset($_POST['radio']))  {
			$selected_radio = $_POST['radio'];
			
			if ($selected_radio == 'index') 
			{
				$index_checked='checked';
				$query="select * from student where stindex = $search";
		$result= mysqli_query($con, $query);
		$strow= mysqli_fetch_array($result);
		
				
		while($strow= mysqli_fetch_array($result))

    
{
    	echo "
		".$strow ['stindex']."	".$strow['first_name']."	".$strow['last_name']."	";
}
				echo($result);
			}
			
		elseif ($selected_radio == 'fname')
			{
				$fname_checked='checked';
				$query="select * from student where first_name ='$search'";
		$result= mysqli_query($con, $query);
		$strow= mysqli_fetch_array($result);
				
		while($strow= mysqli_fetch_array($result))

    
{
    	echo "
		".$strow ['stindex']."	".$strow['first_name']."	".$strow['last_name']."	";
}
				echo($result);
	}
			
			elseif($selected_radio == 'lname')
			{
				$lname_checked='checked';
				
				$query="select * from student where last_name ='$search'";
		$result= mysqli_query($con, $query);
		$strow= mysqli_fetch_array($result);
				
				while($strow= mysqli_fetch_array($result))

    
{
    	echo "
		".$strow ['stindex']."	".$strow['first_name']."	".$strow['last_name']."	";
}
				echo($result);
	}
			}
		
	function filterTable($query)
	{
		$filter_result= mysqli_query($con , $query);
		return $filter_result;
	}
	}
		
?>













<!doctype html>


<meta charset="utf-8">
<title>Search system




	
Search Key

<p>
<input type="radio" name="radio"value='index'<?php print($index_checked);?>>
By Index	
</p><p>
<input type="radio" name="radio"value='fname'<?php print($fname_checked);?>>
By First-Name
</p><p>
<input type="radio" name="radio"value='lname'<?php print($lname_checked);?>>
By Last-Name
</p><p>


</p><p>



</p>
  
        
	<table width="100%" border="2"><tbody><tr>      <th>index</th>      <th>first name</th>      <th>last name</th>    </tr></tbody></table>

推荐答案

con = mysqli_connect(' localhost'' root'' '' gb8');
if (mysqli_connect_error()){
die( 连接失败 .mysqli_connect_error());
}
con= mysqli_connect('localhost' , 'root' , '' , 'gb8'); if (mysqli_connect_error()) { die ("Connection failed" . mysqli_connect_error()); }


index_checked = ' 未选中';
index_checked='unchecked';


fname_checked = ' 未选中';
fname_checked='unchecked';


这篇关于我如何编码搜索页面,结果将以表格形式显示在同一页面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆