Jump to content

Getting and filter results from MySQL ? - Help Needed


BlackTyger

Recommended Posts

Here is my HTML code:

 


<html>
<head>
<title>Simple Search Form</title>
</head>
<body>
   <form name="searchform" method="get" action="/search.php">

        Select Gender: 
        <select name="gender">
                <option value="Male">Male</option>
                <option value="Female">Female</option>
        </select>

        Select City: 
        <select name="gender">
                <option value="all">All Cities</option>
                <option value="newyork">New York</option>
                <option value="toronto">Toronto</option>
                <option value="london">London</option>
                <option value="paris">Paris</option>
        </select>

   <form>
</body>
</html>

 

Here is my PHP code:

 

<?php

// get the data from the search form 

# get the gender (male or female)
$gender = $_GET['gender']; 

# get the city
$city = $_GET['city'];

// connect to mysql and select db
mysql_connect('localhost', 'root', 'pass') or die(mysql_error());
mysql_select_db($test_db);

// send query
$query = mysql_query("SELECT * FROM `visitors_location` WHERE gender='$gender' AND city='$city'");
$count = mysql_num_rows($query);

// display data
while ( $show = mysql_fetch_assoc($query) ) {

          echo $gender . " " . $city;

}

?>

 

My script basically shows # of males or females in a specific city. How can I show all males in all cities? In other words, let's say I want to show # of Females from all those 4 cities combined. I don't know how to do that. Can someone please help me?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.