Hello
I am learning PHP. I need help with the following code:
I have a phpmyadmin database with following fields: id, coursename, coursecode, coursedescription, instructor , courseyear , coursesemester,building, room.
I want to create a php page including a basic drop-down menu to sort the phpmyadmin table.
So far, I have created the drop-down menu form.
I have written the php code that displays all records within the database.
However I couldn`t tie the drop-down menu to the actual table records. Meaning that, when I pick a category from the drop-down menu(lets say I want to list courses in fall2008 or I want to show courses that John Doe teaches) it doesnt work. It always shows all records in the database.
I will really appreciate if you can help me out.
Best,
database connection part
<?php
session_start();
include_once("x.php");
$db = new Database("localhost", "xxx", "yyy", "zzz")or trigger_error(mysql_error(),E_USER_ERROR); ?>
form part:
<div class="pulldown">
<form method="GET" action="<?=$self?>" name="courseselect" >
Courses by:
<select id="q" name="q">
<optgroup label="Semesters">
<option value="fall2008" >Fall</option>
<option value="spring2008" >Spring</option>
<option value="summer2008" >Summer</option>
</optgroup>
<optgroup label="Instructors">
<option value="john">John Doe</option>
<option value="mary">Mary White</option>
<option value="tom">Tom Sawyer</option>
</optgroup>
</select>
<input type="submit" value="show »" />
</form>
</div>
php part:
<?
$result = mysql_query("SELECT DISTINCT id, coursename, coursecode, coursedescription, instructor, courseyear, coursesemester, building, room FROM coursesnew WHERE crse IN ( '2100', '2102', '2104') ORDER BY crse ASC;");
while( $c = mysql_fetch_object($result)) {
printf( '<div class="info">
<br><h2>%s%s - %s</h2><br>
%s <br />
</div>',
$c->coursename, $c->coursecode, $c->instructor, $c->room);
}
?>