Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

filter result by dropdown options

Links for php scripts

Moderators: macek, egami, gesf

filter result by dropdown options

Postby kanonyqkaskdn » Tue Apr 09, 2013 1:20 am

I try to show some data by dropdown option from mySQL

when the user choose option United states and click submit, the page will go to the next page and show the data only for United states

here is my code for test.html

Code: Select all
<body>
   <form action="showDB.php" method="post">
   <table border="0">
   <tr>
      <th>test</th>
   </tr>
   <tr>
      <td>Select Foreign Agent Country</td>
      <td></td>
      <td>
      <select>
      <option name="country" value="US">United States</option>
      <option name="country" value="AUD">Australia</option>
      </select>
      </td>
     </tr>
      <td>
      <button type="submit" name="btn_submit"><a href="showDB.php">Click</a></button>
      </td>
   </table>
   </form>

</body>


here is my second page showDB.php

Code: Select all
<?php
//connect to server
$connect = mysql_connect("localhost", "root", "");

//connect to database
//select the database
mysql_select_db("asdasd");

//query the database
$query = mysql_query("SELECT * FROM auip_wipo_sample");
if(isset($_POST['country'] == 'US')) { 
    // query to get all US records 
    $query = mysql_query("SELECT * FROM auip_wipo_sample WHERE wipo_applicant1_country='US'"); 

elseif(isset($_POST['country'] == 'AUD')) { 
    // query to get all AUD records 
    $query = mysql_query("SELECT * FROM auip_wipo_sample WHERE wipo_applicant1_country='AU'"); 
} else { 
    // query to get all records 
    $query = mysql_query("SELECT * FROM auip_wipo_sample"); 

//fetch the result
Print "<table border cellpadding=3>";
while($row = mysql_fetch_array($query))
{
   Print "<tr>";
   Print "<th>high:</th> <td>".$row['invention_title'] . "</td> ";
   Print "<th>lower:</th> <td>".$row['invention-title'] . " </td></tr>";
}
Print "</table>";
?>


however, I got an error

Parse error: syntax error, unexpected T_IS_EQUAL, expecting ',' or ')' in C:\xampp\htdocs\fak_ict1999\showDB.php on line 11

and line 11 is
Code: Select all
if(isset($_POST['country'] == 'US')) {   


anyone can solve this?? :help:
thanks
kanonyqkaskdn
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Apr 08, 2013 6:01 am

Re: filter result by dropdown options

Postby sandeep605085 » Tue Apr 09, 2013 2:32 am

if(isset($_POST['country'] == 'US')) { }

here isset is not close correctly.
it should be
if ( isset($_POST['country']) == 'US' ) { }

and same issue is there in else part too.

thanks.
Last edited by sandeep605085 on Thu Apr 11, 2013 10:34 pm, edited 1 time in total.
User avatar
sandeep605085
New php-forum User
New php-forum User
 
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions

Re: filter result by dropdown options

Postby swarups » Tue Apr 09, 2013 3:17 am

Hi kanonyqkaskdn

I found you have written four queries in 'showDB.php' for same requirement. You can not write a query for each countries in the drop-down. You can write a common query which will work for all countries in drop-down.

Hope the code below will help you:

Code: Select all
<?php
//connect to server
$connect = mysql_connect("localhost", "root", "");

//connect to database
//select the database
mysql_select_db("asdasd");

//query the database
if(isset($_POST['country'])) { 
     $country = $_POST['country'];
    // query to get all US records 
    $query = mysql_query("SELECT * FROM auip_wipo_sample WHERE auipo_applicant1_country = '$country'");
}
 else { 
    // query to get all records 
    $query = mysql_query("SELECT * FROM auip_wipo_sample"); 

//fetch the result
Print "<table border cellpadding=3>";
while($row = mysql_fetch_array($query))
{
   Print "<tr>";
   Print "<th>high:</th> <td>".$row['invention_title'] . "</td> ";
   Print "<th>lower:</th> <td>".$row['invention-title'] . " </td></tr>";
}
Print "</table>";
?>
swarups
New php-forum User
New php-forum User
 
Posts: 20
Joined: Tue Mar 06, 2012 11:05 pm


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron