Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
<?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;
	}
	}
		
?>




HTML
<!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>
Posted
Updated 4-May-18 7:34am
v3

1 solution

Well - if you wish to see your data in a table you need to actually make a table.

I didn't see that anywhere on your page - so why should the browser do it?

You seem to need a lot of help:
Try HTML Tutorial[^] to start.

If the code you submitted is not your own - this is not the place to come to have someone do the development work for you. Maybe it is yours. Learning php without understanding HTML, however unlikely, was probably unwise.
 
Share this answer
 
Comments
Member 13812035 4-May-18 15:24pm    
i already put the header columns of the table but i don't want to display the rows in the code i want it to connect it with a certain table in my database and bring the records from it.
and no this code mine but i start learning the php recently so there are many things i still don't know
W Balboos, GHB 7-May-18 6:19am    
If you want the search results to be triggered from your table you need to populate the table with reference to the links (link or AJAX). I would use AJAX.

However, if you just started learning PHP, you should spend some time learning it before you make a project spanning so many features. The expression "crawl before you can walk; walk before you can run". AJAX calls php through javaScript.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900