Looking for advice on the following. I have a dynamic php page that connects to another dynamic php page and executes info depending on the var selected.
The vars need to be in a while loop but it is tricky to store each in a session. Also when I click a var and go to the next page, how do I check the var I selected? It was also suggested I store the sessions in an array but again how do I perform a check on the next page.
Code below
page1
<?php
$db=mysql_connect("localhost", "root", "compsci");
mysql_select_db("project", $db);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Student Portal</title>
</head>
<body>
<ul>
<?php
$result = mysql_query("SELECT * FROM degreeprogrammes");
while($row = mysql_fetch_array($result)) {
$faculty = $row[0];
if ($faculty != "") {
//link to faculty folder
echo "<li><a href='".$faculty."'>".$faculty."</a></li>";
$facultyName[] = $falculty;
}
}
$_SESSION['falcultyName'] = $facultyName;
?>
</ul>
</body>
</html>
page2
<?php
$db=mysql_connect("localhost", "root", "compsci");
mysql_select_db("project", $db);
session_start();
$fac = $_SESSION['facultyName']
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Student Portal</title>
</head>
<body>
<ul>
<?php
$result = mysql_query("SELECT * FROM degreeprogrammes WHERE facultyName = '$fac'");
while($row = mysql_fetch_array($result)){
$degree1 = $row[3];
$degree2 = $row[4];
$degree3 = $row[5];
$degree4 = $row[6];
$degree5 = $row[7];
$degree6 = $row[8];
}
if ( $degree1 != "") { echo "<li><a href='$degree1/'>$degree1</a></li>"; }
if ($degree2 != "") { echo "<li><a href='$degree2/'>$degree2</a></li>"; }
if ($degree3 != "") { echo "<li><a href='$degree3/'>$degree3</a></li>"; }
if ($degree4 != "") { echo "<li><a href='$degree4/'>$degree4</a></li>"; }
if ($degree5 != "") { echo "<li><a href='$degree5/'>$degree5</a></li>"; }
if ($degree6 != "") { echo "<li><a href='$degree6/'>$degree6</a></li>"; }
?>
</ul>
</body>
</html>
If anyone knows a better, easier way to do this also please let me know