dannyone
-
Posts
57 -
Joined
-
Last visited
Never
Posts posted by dannyone
-
-
hello everyone, currently i have a drop down menu that displays all the students that the logged in marker is teaching. now i want the marker to be able to select the student that they are marking from the list and once selected view the timetable for that student. its seems really complicated, and i have been working on it for a while now, so if any1 could help it'd be brilliant! heres my code so far:
<?php
require_once('auth1.php');
require_once('config.php');
?>
<h4><?php echo $_SESSION['SESS_FIRST_NAME'], " ".$_SESSION['SESS_LAST_NAME'];?>, the students you are marking are;</h4>
<form action="" method="POST">
<?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 for the combo box
$query="SELECT Student,FName,LName FROM Student_Markers,Student WHERE Student_Markers.Student = Student.Student_ID AND Marker1 = '" .$_SESSION['login'] . "'";
$result = mysql_query ($query);
echo "<select Student=Student value=''>Student</option>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){
//Array or records stored in $nt
echo "<option value=$nt[student]>$nt[student], $nt[FName], $nt[LName]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>
<input type="submit" value="View Timetable and Details" />
viewing the student timetable
<?php
// Create an array of days
$days = array('mon' => '', 'tue' => '', 'wed' => '', 'thu' => '', 'fri' => '');
// Add our list of days to our time slots
$times = array(
'9-10' => $days,
'10-11' => $days,
'11-12' => $days,
'12-1' => $days,
'1-2' => $days,
'2-3' => $days,
'3-4' => $days);
// Connect to DB and run our query
$sql = new mysqli('localhost', 'danny', 'danny', 'tutorial');
$run = $sql->query("SELECT
s.Student_ID,
c.course_id,
c.time_slot,
c.RoomName,
c.Semester_ID,
c.day
FROM
Student AS s
INNER JOIN
Student_Course AS sc
ON (s.Student_ID = sc.Student_ID)
INNER JOIN
Course AS c
ON (c.course_id = sc.course_id)
INNER JOIN
Student_Markers AS sm
ON (sc.Student_ID = sm.Student)
WHERE
sm.Student = '$nt' AND c.Semester_ID = 'Semester1'");
while($row = $run->fetch_object())
{
$times[$row->time_slot][$row->day] = "$row->course_id<br />$row->RoomName";
}
$body = <<< endBody
<center>
<table align="center" border="1" cellspacing="0" cellpadding="1">
<tr>
<th align="center">Time</th>
<th align="center">Monday</th>
<th align="center">Tuesday</th>
<th align="center">Wednesday</th>
<th align="center">Thursday</th>
<th align="center">Friday</th>
</tr>
endBody;
// For each time slot, check each day for a value
// If one exists, display it, if not, display an empty table data (<td>)
foreach($times as $timeslot => $day)
{
$body .= "\n\t\t<tr>\n\t\t\t<td>$timeslot</td>";
foreach($day as $course)
{
$td = (strlen($course) > 0) ? $course : ' ';
$body .= "\n\t\t\t<td>$td</td>";
}
$body .= "\n\t\t</tr>";
}
$body .= "\n\t</table>\n</center";
?>
<?=$body?>
thanks
Danny
-
im really sorry but i dnt get what u mean by start using $login and $password, can you show me an example or point me in the right direction? should i stop using clean?
thanks
Danny
-
thankyou both for you replys, i have tried to use both of ur codes but i cant get them working :S below i have put how i am storing the Student_ID, i think i am storing it in .$login.?? but not 100% sure im a bit of a noob.. can you have a quick look an see if thats right please?
//Sanitize the POST values
$login = clean($_POST['login']);
$password = clean($_POST['password']);
//Create query
$qry="SELECT * FROM Student WHERE Student_ID=".$login." AND Password='".md5($_POST['password'])."'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['id'];
$_SESSION['SESS_STUDENT_ID'] = $member['Student_ID'];
$_SESSION['SESS_FIRST_NAME'] = $member['FName'];
$_SESSION['SESS_LAST_NAME'] = $member['LName'];
$_SESSION['login'] = $login;
session_write_close();
thanks again
Danny
-
iv been at this for about a week now and i still can't get my head around it. i need to link three tables together; Student, Course, Student_Course.
i need to get Student.Student_ID, Course.course_id, Course.time_slot, Course.RoomName, Course.day AND Student.Student_ID=Student_Course.Student_ID and Course.course_id=Student_Course.course_id.
the problem is, i also need to make this query specific to the user that has logged in, so Student_ID=$login.
can some1 help me out an show me where i am going wrong? im really stuck
$sql = new mysqli('localhost', '1', '2', 'tutorial');
$run = $sql->query("SELECT Student.Student_ID,Student_Course.Student_ID,Student_Course.course_id,Course.course_id,Course.time_slot,Course.RoomName,Course.day FROM Student,Student_Course,Course WHERE Student_ID=".$login." AND Student.Student_ID=Student_Course.Student_ID AND Student_Course.course_id=Course.course_id");
while($row = $run->fetch_object())
{
$times[$row->time_slot][$row->day] = "Course: $row->course_id<br />Room: $row->RoomName";
}
thanks in advance
Danny
-
ok im a little stuck on this, i am trying to collect all of the course_id's, time_slots, RoomName and days from a table, for a specific logged in user. im using a sessions and storing the student_id in a variable $login.
i have 3 tables, Student, Course, Student_Course
Student:
Student_ID <-- collects student_ID from here and stores in $login
Course:
course_id, RoomName, Time, Day
Student_Course:
Student_ID, course_id
a student takes 3 courses 3 times a week, and a need to return all courses, times rooms and dates, can someone have a look an see where i am going wrong please
it'd be great if some1 could help heres my code:
<?php
require_once('auth.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>My Profile</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>My Profile </h1>
<a href="member-index.php">Home</a> | <a href="student_logout.php">Logout</a>
<p>This is another secure page. </p>
<?php
echo '<div class="details">';
echo '<div class="detailsleft">';
echo '<h6><em>Your Details:</em></h6>';
$result=mysql_query("SELECT * FROM Student,Course,Student_Course WHERE Student.Student_ID=Student_Course.Student_ID,Course.course_id=Student_Course.course_id AND Student.Student_ID='$login'");
$row=mysql_fetch_array($result);
echo '<p><b>Course id:</b> '.$row['course_id'].'</p>';
echo '<p><b>Time:</b> '.$row['Time_slot'].'</p>';
echo '<h6><em>Timetable:</em></h6>';
echo '<p><b>Room Name:</b> '.$row['RoomName'].'</p>';
echo '<p><b>First Name:</b> '.$row['FName'].'</p>';
echo '<p><b>Day:</b> '.$row['day'].'</p>';
echo '</div>';//details div left
echo '<div class="detailsright"><p>';
echo '</p>';
echo '</div>';//details div right
echo '</div>';//details div
echo '</div>';//main div
?>
</body>
</html>
thanks in advance
Danny
-
hello everyone, i am really struggling with the concept on doing multiple querys and returning data if it matchs.
i am trying to get a user to log in using a session, then search two tables:
timetable table:
id, course_id, RoomName,time_slot,day
Student_ID table:
id, Student_ID, FName, LName, module1, module2, module3, module4, module5, module6, module7
i am trying to get the query to display the timetable for the student in a table, were Student_ID.module1 == timetable.course_id, Student_ID.module2 == timetable.course_id etc...
can anyone help me with this? here is my attempt at it so far, it current output is a table showing all of the courses listed in timetable, i need it to only display the ones that the student has logged in is taking.
my code:
<?php
session_start();
if(!session_is_registered(myusername)){
header("location:Template.html");
}
$myusername = ($_GET['myusername']);
// Create an array of days
$days = array('mon' => '', 'tue' => '', 'wed' => '', 'thu' => '', 'fri' => '');
// Add our list of days to our time slots
$times = array(
'9-10' => $days,
'10-11' => $days,
'11-12' => $days,
'12-1' => $days,
'1-2' => $days,
'2-3' => $days,
'3-4' => $days,
'4-5' => $days,
'5-6' => $days);
// Connect to DB and run our query
$sql = new mysqli('localhost', 'user', 'pass', 'Timeslot_Allocation');
$run = $sql->query ("SELECT * FROM timetable");
while($row = $run->fetch_object())
{
// $times[$row->time_slot][$row->day] = "modules: $row->$course_id<br />Room: $row->RoomName";
$times[$row->time_slot][$row->day] = "modules: ".$row->course_id."<br>Room: ".$row->RoomName;
}
mysql_connect("localhost", "user", "pass");
mysql_select_db("Timeslot_Allocation")or die(mysql_error());
$query = "SELECT Student_ID.module1, Student_ID.module2, Student_ID.module3, Student_ID.module4, Student_ID.module5, Student_ID.module6, Student_ID.module7, timetable.course_id, timetable.time_slot, timetable.RoomName, timetable.day ".
"FROM Student_ID, timetable ".
"WHERE Student_ID.module1 = timetable.course_id AND Student_ID.module2 = timetable.course_id AND Student_ID.module3 = timetable.course_id AND Student_ID.module4 = timetable.course_id AND Student_ID.module5 = timetable.course_id AND Student_ID.module6 = timetable.course_id AND Student_ID.module7 = timetable.course_id ";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$slot[$result->module1][$result->course_id];
$slot[$result->module2][$result->course_id];
$slot[$result->module3][$result->course_id];
$slot[$result->module4][$result->course_id];
$slot[$result->module5][$result->course_id];
$slot[$result->module6][$result->course_id];
$slot[$result->module7][$result->course_id];
}
$body = <<< endBody
<center>
<table border="1" cellspacing="0" cellpadding="2">
<tr>
<th>Time Slot</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
</tr>
endBody;
// For each time slot, check each day for a value
// If one exists, display it, if not, display an empty table data (<td>)
foreach($times as $timeslot => $days)
{
$body .= "\n\t\t<tr>\n\t\t\t<td>$timeslot</td>";
foreach($days as $slot)
{
$td = (strlen($slot) > 0) ? $slot : ' ';
$body .= "\n\t\t\t<td>$td</td>";
}
$body .= "\n\t\t</tr>";
}
$body .= "\n\t</table>\n</center";
echo $body;
?>
thanks in advance
Danny
Select If Statement help
in PHP Coding Help
Posted
hello everyone, i have this select statement that displays all the students that the logged in marker is marking(Student_Markers table). now when a mark clicks on a student in the list i want it to display that students details from a seperate (Students) table where Students.Student_ID = Student_Markers.Student_ID).
i think i would need to use a if else statement, but i don't understand how to do it. could some1 please help? i need another query to do;
if $nt = Student.Student_ID then display FName, LName etc...
heres what i have done so far...
$query="SELECT Student,FName,LName FROM Student_Markers,Student WHERE Student_Markers.Student = Student.Student_ID AND Marker1 = '" .$_SESSION['login'] . "'";
$result = mysql_query ($query);
echo "<select Student=Student value=''>Student</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[student]>$nt[student], $nt[FName], $nt[LName]</option>";
}
echo "</select>";
any help would be great
thanks