Thursday, 17 March 2016

search example on selection wise search

How to write code  for following example  suppose
(1) if 
You   select  city Mumbai then it will display only city Mumbai record
(2)if you select country   India  then it will display only  country  India record
(3)if you select both city=Mumbai and country=India  then it will  record where Mumbai and India is matched..together..

(1)create table details :
create  table  details
(id   int    primary   key   auto_increment ,
 city  varchar(20),
 country  varchar(20)
 );
(2)write code for  search.php file given below :

<form action=search.php method=post>
                City        :<input type=text name=city>
                Country                :<input type=text name=country>
                <input type=submit name=submit value=Filter>
</form>
<?php
if(isset($_POST['submit']))
{
                $city=$_POST['city'];
                $country=$_POST['country'];
                $con=mysql_connect('localhost','root','');
                mysql_select_db('abhi',$con);
                if($_POST['city']==true && $_POST['country']==false)
                {
                                $sql="select * from details where city='$city'";
                                $result=mysql_query($sql);
                                echo '<table border=5><tr><td>Id</td><td>City</td><td>Country</td></tr>';
                                while($row=mysql_fetch_array($result))
                                {
                                                echo '<tr>';
                                                                echo '<td>';
                                                                                echo $row['id'];
                                                                echo '</td>';
                                                                echo '<td>';
                                                                                echo $row['city'];
                                                                echo '</td>';
                                                                echo '<td>';
                                                                                echo $row['country'];
                                                                echo '</td>';
                                                echo '</tr>';
                                }
                                echo '</table>';
                }
               
                else if($_POST['city']==false && $_POST['country']==true)
                {
                                $sql="select * from details where country='$country'";
                                $result=mysql_query($sql);
                                echo '<table border=5><tr><td>Id</td><td>City</td><td>Country</td></tr>';
                                while($row=mysql_fetch_array($result))
                                {
                                                echo '<tr>';
                                                                echo '<td>';
                                                                                echo $row['id'];
                                                                echo '</td>';
                                                                echo '<td>';
                                                                                echo $row['city'];
                                                                echo '</td>';
                                                                echo '<td>';
                                                                                echo $row['country'];
                                                                echo '</td>';
                                                echo '</tr>';
                                }
                                echo '</table>';
                }
                else if($_POST['city']==true && $_POST['country']==true)
                {
                                $sql="select * from details where city='$city' and country='$country'";
                                $result=mysql_query($sql);
                                echo '<table border=5><tr><td>Id</td><td>City</td><td>Country</td></tr>';
                                while($row=mysql_fetch_array($result))
                                {
                                                echo '<tr>';
                                                                echo '<td>';
                                                                                echo $row['id'];
                                                                echo '</td>';
                                                                echo '<td>';
                                                                                echo $row['city'];
                                                                echo '</td>';
                                                                echo '<td>';
                                                                                echo $row['country'];
                                                                echo '</td>';
                                                echo '</tr>';
                                }
                                echo '</table>';
                }
                else
                {
                                echo "No record";
                }
                }

?>

Browsers

Powered by Blogger.

Feature Post

About Me

My photo
B.E.(COMPUTER ENGINEER) PHP Web developer & Provide Training for Web Development , Digital Marketing ,Android Mobile Apps Development

Post Slider (Homepage)

Blog Archive

Malwares

Transfer Files

Media Players

Download Manager

Window

Torrents Soft

Developer Tools

Botton Ad

Ads

Newsletter

 

© 2013 PHP TRAINING IN MUMBAI BY OM SIR . All rights resevered. Designed by OM SIR

Back To Top