Hey everybody!
I am trying to build a MySQL database of Fans for a local band, so that I can mail them out a newsletter. I am trying to get it so that I can have a dropdown menu with all the locations loaded into it, then it will open a table with all the people in that area.
I have managed to get it so that it does that so far, however, it is showing an option for EVERY result, rather than filtering out the ones that are the same as each other, is there any way that I can get it to see if there is more than 1 result and then just display that as one option??
If anyone knows what I mean, I would be very pleased if they could tell me the answer!
Thanks
Here is the code I am using at the mo:
This is the main page, which contains the form
PHP Code:
<?php
// include the headers for jakeandelwood.co.uk
include 'jakeandelwood.html';
?>
<?php
// This is a small program designed to query a MySQL database
// to draw up email addresses based on location, it uses a simple
// way of querying the database (included in email.php), this
// script should run off any database, as long as you have a little
// knowledge of PHP and MySQL and are able to change the appropriate
// fields in the script and on your MySQL database
?>
<?php
// Check to see if the post variable is present, if not load the form
if ($_POST) {
include 'email.php';
} else { ?>
<h1>Database look up</h1>
<b>Please use the drop down box below to find email addresses that belong to people in different areas!</b><br><br>
<center>
<form action="index.php" method="post">
<select name="county">
<?php
}
?>
<?php
// Open a mysql connection
include 'includes/mysql.php';
$select1 = "SELECT town_city FROM locations";
$result1 = mysqli_query($link, $select1);
// loop through to bring up all the database locations
while ($row = mysqli_fetch_array($result1)) {
$town_city = $row['town_city'];
echo "<option>".$town_city."</option>";
}
?>
This is the table page with the results:
PHP Code:
<?php
// include the details of the mysql database
include 'includes/mysql.php';
$input = $_POST['county'];
?>
<!--Set up a table-->
<table border="1" cellpadding="5">
<tr>
<th>Database ID</th>
<th>Name</th>
<th>E-mail address</th>
<th>Town/City</th>
<th>County</th>
<th>Status</th>
</tr>
<?php
// build and execute the query
$select = "SELECT id, name, email, town_city, county, status FROM locations WHERE county=\"$input\"";
$result = mysqli_query($link, $select);
//loop through the results
while ($row = mysqli_fetch_array($result)) {
//get each element and put it in a variable
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$town_city = $row['town_city'];
$county = $row['county'];
$status = $row['status'];
//Print out the results
echo <<<END
<TR>
<TD>$id</TD>
<TD>$name</TD>
<TD><A HREF="mailto:$email">$email</A></TD>
<TD>$town_city</TD>
<TD>$county</TD>
<TD>$status</TD>
</TR>
END;
}
?>
<!--End the Table-->
</TABLE>
<?php
mysqli_close($link);
?>
This is the connection data:
PHP Code:
<?php
// Open connection with the MySQL database
$link = mysqli_connect('localhost','USERNAME','PASSWORD','DATABASE');
?>
Thanks