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?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.