Hi,
I have a search form that picks users of class name of course name. Now I have a problem viewing data in categorization from mysql database with php. For Example I need the following:
Course Name: Name
Class Name: Name
1. Name Surname(User)
2. Name Surname(User)
3. Name Surname(User)
Course Name: Name1
Class Name: Name1
1. Name Surname(User)
2. Name Surname(User)
3. Name Surname(User)
etc
What I have till now is:
<form method="post" action="membersearch.php?go" id="searchform">
<input type="text" name="name" />
<input type="submit" name="submit" value="Search" />
</form>
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){
$name=$_POST['name'];
//Include database connection details
require_once('config.php');
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
//-query the database table
$sql="SELECT * FROM (`tblmembers` as tm left join `tblclass` as tc on tm.ClassID = tc.ClassID) LEFT JOIN `tblcourse` as tco on tc.CourseId=tco.CourseID WHERE tm.MemberSurname LIKE '%" . $name . "%' OR tm.MemberName LIKE '%" . $name . "%' OR tc.ClassName LIKE '%" . $name . "%' OR tco.CourseName LIKE '%" . $name . "%'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$FirstName=$row['MemberName'];
$LastName=$row['MemberSurname'];
$ID=$row['Username'];
$ClassName=$row['ClassName'];
$CourseName=$row['CourseName'];
//-display the result of the array
echo "<ul>";
echo "<li style='list-style:none; font-size:14px; line-height:30px'><b> Course Name:</b> $CourseName";
echo "<ul>";
echo "<li style='font-size:12px; line-height:30px'><b> Class Name:</b> $ClassName";
echo "<ol>\n";
echo "<li>" . "<a href=\"membersearch.php?id=$ID\">" .$FirstName . " " . $LastName . "</a></li>\n";
echo "</ol>";
echo "</li>";
echo "</ul>";
echo "</li>";
echo "</ul>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
} }
The above is showing as follows:
Course Name: Name
Class Name: Name
1. Name Surname(User)
Course Name: Name
Class Name: Name
1. Name Surname(User)
Course Name: Name1
Class Name: Name1
1. Name Surname(User)
It is basically showing every user per class Name and I need that all students in a class name will be listed under each other. Is this possible please?
N.B. Apologies if I have explained myself difficulty. If you don't understand something please let me know.
Thanks in advanced