Struggling with Drop Down List and Results Display
Posted: Wed Apr 04, 2007 8:56 pm
feyd | Please use
Now at least this populates the drop down list with the councils.
So now if I create a file called 'stupidity.php'. What's needed? A connection to the database, a table with rows along the lines of: td>Council</td>
<td><? echo $council; ?></td>?
What else?
I'm missing something REALLY basic here aren't I? And yet my mind is now mush after searching for the answer and alas I have hope in the goodness of this forum!!
Any help?
Any help appreciated!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm new to php but have been progressing using books and the Internet as well as reading this and other forums but am stuck.
I am putting together a website. I've created a mysql/php database. In a database called 'councils' I have a table called 'councildata'.
In councildata there are 14 columns including the 'ID' field.
I've managed to populate a drop down selection box derived from the database which shows a list of every council. There are currently 60 councils entered.
[b]The result I want now is: [/b]When a site visitor selects a council (or councils if multiple) using the drop-down box and selects 'submit', they see a page with the information they were looking for, relevant to that council.
[b]For example: [/b]
User selects Council 'A' and submits form.
[i][b]Page appears with:[/b][/i]
[b]Council: [/b]Council 'A'
[b]Address:[/b] Address pulled from database
[b]Town or City: [/b]Town pulled from database
[b]Postcode: [/b]Postcode pulled from database
etc., etc.
[b]I've managed to populate the drop down list with this code (below) [/b]- which may or may not be ideal and might be the reason I can't get the next page to display:Code: Select all
<?php
$username="xxxxxxx";
$password="xdxxxxx";
$database="xxxxxxxxx";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM councildata";
$result=mysql_query($query);
function generate_box() {
$sql = "SELECT * FROM councildata";
$result = mysql_query($sql);
$entries = mysql_num_rows($result);
for($n = 0; $n <= $entries; $n++) {
$sql = "SELECT * FROM councildata WHERE ID = $n";
$result = mysql_query($sql);
while ($info = mysql_fetch_array($result)) {
foreach( $info AS $key => $val ) {
$$key = stripslashes( $val );
}
$options .= "<option value=\"-1\">$council</option>";
$options .= "<option value=\"-1\"></option>";
}
}
return $options;
}
$options = generate_box();
?>
<form method="get" name="form_select" action="stupidity.php"><table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><span>Search By:
<select name="by">
<? echo "$options"; ?>Now at least this populates the drop down list with the councils.
So now if I create a file called 'stupidity.php'. What's needed? A connection to the database, a table with rows along the lines of: td>Council</td>
<td><? echo $council; ?></td>?
What else?
I'm missing something REALLY basic here aren't I? And yet my mind is now mush after searching for the answer and alas I have hope in the goodness of this forum!!
Any help?
Any help appreciated!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]