I’m a PHP beginner learning through online tutorials and need some help:
On my index.php file I’ve got a dynamic drop down list which displays the “university” names and when the form is submitted, it should output from my databse: the “content”, “post_code” and “borough” in my result.php. Unfortunately, all I’ve managed to display is the name of the university which is assigned to the "select value". Can I please have assistance on how to output all the database info based on the “select” university?
I’ve got a database called "map" with the following table:
id
university
position
visible
content
post_code
borough
My index.php file has the following code:
Code: Select all
<?php
// Connect database
mysql_connect("localhost","root","xxx");
mysql_select_db("map");
// If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
if(isset($select)&& $select!=""){
$select=$_GET['select'];
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form id="form1" name="form1" method="post" action="result.php"">
Search by borough :
<select name="select">
<option value="">--- Select ---</option>
<?php
// Get records from database (table "subjects").
$list=mysql_query("SELECT * FROM subjects ORDER BY id ASC");
// Show records by while loop.
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<?php echo $row_list['university']; ?>" <?php if($row_list['id'] == '$select'){ echo "selected"; } ?>><?php echo $row_list['university']; ?></option>
<?php
// End while loop.
}
?>
</select>
<input type="submit" name="Submit" value="select" />
</form>
<?php
mysql_close();
?>
</p>
</body>
</html>
Code: Select all
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<html>
<head>
</head>
<body>
The University is: <?php echo $_POST["select"]; ?>
The Postcode is:
The content (university description is):
</body>
</html>