Im looking to create a similar procedure to this forum whereby when you click a thread you run a query which effectively lists all the responses. Ive been trying all day now to develop a solution with no luck.
My table (trainingtopics) is:
coursecode (primary_key)
coursename
elearning
facetoface
blended
etc
I have a list of coursenames and now I would like to click each one and see all the corresponding details.
This is my first page called elearningcourses which lists all courses using a query and the href function:
<?php
$user = "root";
$host = "localhost";
$password = "";
$connection = mysql_connect($host, $root, $password) or die ("Couldn't connect to server.");
$database = "courses";
$db = mysql_select_db($database) or die ("Couldn't select database.");
$sql = "SELECT coursename FROM trainingtopics";
//echo $sql."<br>";
$result = mysql_query($sql) or die(mysql_error());
echo $result."=result<br>";
while($row=mysql_fetch_array($result))
{ // NOTE this one ABOVE the echo
//echo "result found!";
//echo $row[0];
echo "<a href=\"details.php?course=".$row[0]."\">".$row[0]."</a><br>";
}
?>
And here is what I have for the details.php page which is supposed to expand on the chosen coursename in elearningcourse.php and show all the records such as elearning/facetoface/blended etc.
<?php
if (isset($_GET['course'])) {
$user = "root";
$host = "localhost";
$password = "";
$connection = mysql_connect($host, $root, $password) or die ("Couldn't connect to server.");
$database = "courses";
$db = mysql_select_db($database) or die ("Couldn't select database.");
$course = mysql_real_escape_string($_GET['course']);
echo $course;
$res = mysql_query("SELECT * FROM trainingtopics WHERE coursename = '$course'");
echo $res;
if ($res && mysql_num_rows($res) != 0) {
// get results from query
// output to browser with echo
} else {
//course name not found
//note: the query may have failed to so maybe check for that.
}
} else {
//no course specified
}
?>
So far sometimes I get a blank page and other times just the chosen coursename is displayed.
HELP!!!!