Welcome! Log In Create A New Profile

Advanced

Project related

Posted by Slinger 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Project related
October 12, 2009 06:32AM
The page is created for an administrator, with a link to the student registration page.
When you go back from this page to the administrator areas do we need a user name and password verification, and if so how do I let
you know what it is for the purpose of marking?
avatar
Mac
Re: Project related
October 12, 2009 11:53AM
You can add it if you want. To make it easy for me (appreciated), just print the login and password on top of the login form - we don't care if it it is seen now. Another probably better way to do it is to have the login and password preset in the form by <input .... name=login value=admin> so I don't even have to type it in.

Having said all of that - remember that the administrator links to the registration page so that they can register a student inbetween their other tasks. Therefore, if you use sessions, then there should be no reason to have to log in again when you return to the page - you have not opened up another browser.
avatar Re: Project related
October 13, 2009 10:04AM
Hi Mac.

I have finished my assignment. Is there any problem with it being 14 different pages? I know the requirements said that you wanted "at least 4 pages".

Just checking.

Thanks
Stanton
avatar
Mac
Re: Project related
October 13, 2009 10:47AM
Nope - as long as it easy easy to navigate between pages, ie. I must get to any page from any page.
avatar Re: Project related
October 13, 2009 10:59AM
Sure no problem. winking smiley
Re: Project related
October 14, 2009 07:01AM
Darwin award for most stupid questions goes to slinger.

Can I still pass if my application doesn't work.?
I don't think I have any chance of passing this course.

Can I get a 2 month extension?

and lastly Can I still ask you for help, or is this like an exam where I'm on my own.?

I am seriously stressed. I don't think I can do this. Where can I get more help, for a stupid?
Google answers is normally way over my head, as is the three text books I own.

What to do
Werner van der Watt
avatar Re: Project related
October 14, 2009 08:23AM
My friend Slinger...

If you are struggling, google is the best friend a man can have.

Also, i found that by making all these pages, as i went along slowly but surely the greek became more and more understandable.

Eventually you see things differently if you just keep trying.

Keep at it and don't give up!

If you are having specific problems, discuss them on the forum smiling smiley

Just my opinion.

Regards
Stanton
Re: Project related
October 14, 2009 11:38AM
I cant seem to list student names under there particular course names.

I can list the student names in a while loop.
I can the list the student names in that same while loop.

But now it lists every student under every subject.
I know that the course_student table is my link.

Where course_student "id" = course "id" will give me a student no.
Where course"sno" = student"sno"

So this It what I think should, work, but It doesn't

<?php
// 1. Connect to database
$connection = mysql_connect ('localhost', 'root', 'root');
if (!$connection) {
die("Database connection failed: " . mysql_error());
}

// 2.Select a database to use

$db_select = mysql_select_db("registration" , $connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}



// 3. Perform database query

$result = mysql_query("SELECT * FROM course", $connection);
if (!$result) {
die("Database query failed: " . mysql_error());
}
//4. Use returned data
while ($row = mysql_fetch_array($result)) {
echo $row["cname"] . " " . "<br/>";


$sno = mysql_query("SELECT * FROM course_student WHERE cid = {$row["id"]}", $connection);
if (!$sno) {
die("Database query failed: " . mysql_error());
}
$snoresult = mysql_fetch_array($sno);


$stud_set = mysql_query("SELECT * FROM student WHERE sno = {$snoresult["sno"]}", $connection);
if (!$stud_set) {
die("Database query failed: " . mysql_error());
}
$student_name = mysql_fetch_array($stud_set);
echo $student_name["sname"] . " " . "<br/>";
}

?>
avatar Re: Project related
October 14, 2009 12:11PM
Perhaps it's because you're doing separate select queries. I did one select query to join all three tables, whereby the info selected is based on which CID is selected.

something like:

$result=mysql_query("select course.cname, student.sno, student.title, student.init, student.fname, student.sname from student, course_student, course where course_student.sno = student.sno and course_student.cid = course.cid and course.cid = '$cid'"winking smiley;

i then did the following statement to output the results into a table with each result then being put on a new line.

while ($row = mysql_fetch_array($result)) {

Seemed to work exactly the way i wanted.
Re: Project related
October 14, 2009 12:16PM
Thanx I'm going to try that.
I finally came right with my round about way.
This works


//4. Use returned data
while ($row = mysql_fetch_array($result)) {
echo $row["cname"] . " " . "<br/>";

$idnum = mysql_query("SELECT * FROM course_student WHERE cid = {$row["cid"]}", $connection);
if (!idnum) {
die("Database query failed: " . mysql_error());
}
$sn = mysql_fetch_array($idnum);


$student_set = mysql_query("SELECT * FROM student WHERE sno = {$sn["sno"]}", $connection);
if (!$student_set) {
die("Database query failed: " . mysql_error());
}

$sname = mysql_fetch_array($student_set);
echo $sname["sname"] . " " . "<br/>";


}


Really really apreciate your input.
I owe you a dop.
avatar Re: Project related
October 14, 2009 12:22PM
Ha ha lekker buddy. Enjoy and good luck with the rest!
Re: Project related
October 14, 2009 12:24PM
Nope That didn't work it stops outputting as soon as it runs out of subject, gonna have to try something else.
Gonna try your way, see how that goes.
avatar Re: Project related
October 14, 2009 12:42PM
cool good luck...

this is my code


echo "<br>Below is a list of student's currently registered for the course.<br><br>";

$result = mysql_list_fields("registration", "student"winking smiley;

echo "<table border='2' width='900' cellspacing='1' cellpadding='1'>";
echo "<tr>";
echo "<td><b>Course Name</b></td>";
echo "<td><b>Student Number</b></td>";
echo "<td><b>Title</b></td>";
echo "<td><b>Initials</b></td>";
echo "<td><b>First Name</b></td>";
echo "<td><b>Surname</b></td>";
echo "</tr>";
$result=mysql_query("select course.cname, student.sno, student.title, student.init, student.fname, student.sname from student, course_student, course where course_student.sno = student.sno and course_student.cid = course.cid and course.cid = '$cid'"winking smiley;



while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td width='20%'>";
echo $row["cname"];
echo "<td width='5%'>";
echo $row["sno"];
echo "<td width='10%'>";
echo $row["title"];
echo "</tr>";
echo "<td width='5%'>";
echo $row["init"];
echo "</tr>";
echo "<td width='10%'>";
echo $row["fname"];
echo "</tr>";
echo "<td width='5%'>";
echo $row["sname"];
echo "</tr>";

echo "</tr>";
echo "</tr>";

echo "</td>";
echo "</tr>";
}
echo "</table>";


hope it's no problem for me to share...
avatar
Mac
Re: Project related
October 14, 2009 04:13PM
While SQL joins are the way to do it - many people struggle with that early on in the programming careers (not stanimal it seems smiling smiley )

So write it as you think it (procedural coding) - and here I give a unrelated example:

Get the id from the db.

Here is the 1st query loop
{
$id==$row["id"];
// enter a new sql query here, using this id to get his name, surname etc which is in another table
.....
echo "$sname, $name....

}

NOW I know that many people will shoot me down for teaching bad habits. I don't care. Work logically first - then sit back and ask yourself - how can I improve this code. It takes some experience to write functions from the start - typically you write code and realize that it is better if you include it into a function (not speaking of the PHP functions that are already written for you - see Appendix C in the handbook - it can greatly reduce your code).

I have no intention to mark you to industry standards. First it must work. Or most of it anyway. Then I look at how you got it to work. Logic counts for as much, if not more, than working code.

And no, if you don't finish, you have to re-register next year (no course fees - just registration fee).
Re: Project related
October 15, 2009 08:14AM
Thanx Mac

I havn't given up yet.
I tried stamina's code, but it doesn't work on my side. (Not saying it doesn't work)
I did read up a lot about joins now, but things don't work.
It could be syntax errors that's giving me problems, or perhaps in my includes or config files.

There is no way I'm giving up, and if I have to "see" you next year I will, but that's not first prize.

Thanx for your input.
I'm punting around your (procedural coding) technique and the lights are on, but no one is home yet.
Re: Project related
October 15, 2009 10:26AM
Hi

I have a question regards Slinger first question, with regards to a Log on screen; i have create one but in order to save passwords and username i need to add a Login Table in SQL in order for this functionality to work...

And i know with not allowed to add extra table or field because MAC may not be able to open it.

May any one be able to assist me in this matter?

Rgds

Radhika
avatar Re: Project related
October 15, 2009 12:06PM
you could always hard code the password info into your php code, and use a login form to process the data?

This way no database manipulation...
Re: Project related
October 15, 2009 02:01PM
Thanks that sound like a great idea
avatar
Mac
Re: Project related
October 15, 2009 02:09PM
Yes - I mark your project using the given database - otherwise I have to create those tables ..... that is not what I want to do smiling smiley
Re: Project related
October 19, 2009 07:47AM
Man this stuff can be frustrating.

I followed this online tutorial to get my join to work, as the textbook wasn't helping me (I thought)
Turns out I called student.cell in my query instead of student.cel. Of course nothing worked.

By luck I checked through the database and my code using two screens and picked up the error.

You got to love it.
avatar
Mac
Re: Project related
October 19, 2009 09:36AM
Typos can and will keep you busy for hours smiling smiley
Re: Project related
October 19, 2009 12:00PM
mac Wrote:
-------------------------------------------------------
> Yes - I mark your project using the given database
> - otherwise I have to create those tables .....
> that is not what I want to do smiling smiley


I was just wondering I saw that you can write a SQL query to create a new table too. So in that case you should be able to create a new table before entering the username and password? Then you do not need to create the table, or am I on the wrong track here?
avatar
Mac
Re: Project related
October 19, 2009 12:50PM
Yes, you can - but I want you to work with the table structure that I provided for various reasons - security being one of them.
avatar Re: Project related
October 19, 2009 01:07PM
Why create an extra table when you could just read/write that info into a text file etc ?
Re: Project related
October 19, 2009 01:39PM
@Mac. Thanx. and yeah fully understand.

@Stanimal - ag was just wondering if it could be done that way. already hardcoded the username and password into the login form so no worries there smiling smiley
avatar Re: Project related
October 19, 2009 02:46PM
Yeah i hard coded mine too, but it's just an option winking smiley
Re: Project related
October 19, 2009 03:47PM
Hi am really enjoying this assignment. Please if someone could clarify registration page for me I enter student details and course details , I have managed to insert student data inthe student table dont know how to insert information into the course-student table as the student number is allocated only after data inserted into student table. Should I first sumit student details then have a another page to register an existing student to course requested.
avatar Re: Project related
October 19, 2009 04:24PM
Well, if you keep it on the same page you could do three separate mysql queries... one which inserts into the student table, then one which reads the student number, then another which inserts that same value into course student.

Well thats how i did it anyway smiling smiley
Re: Project related
October 19, 2009 05:45PM
Thanks for help. Am sorry to ask such silly question am uncertain how to get that new student number that is automatically generated so I can insert into course student table. I know how to add course code into the course-student table.

This is my code to add student details
<?php

$title = "Add Students";
include ("header.php"winking smiley;
require_once 'config.php';
mysql_select_db("project"winking smiley;

$Surname = $_POST['Surname'];
$Initials = $_POST['Initials'];
$Name = $_POST['Name'];
$Title = $_POST['Title'];
$Maiden = $_POST['Maiden'];
$DOB = $_POST['DOB'];
$Gender = $_POST['Gender'];
$Language = $_POST['Language'];
$ID = $_POST['ID'];
$Home_Tel = $_POST['Home_Tel'];
$Work_Tel = $_POST['Work_Tel'];
$Cell = $_POST['Cell'];
$Fax_Tel = $_POST['Fax_Tel'];
$Email = $_POST['Email'];
$Postal = $_POST['Postal'];








$query = "INSERT INTO student VALUES (' ' ,'$Surname', '$Initials', '$Name', '$Title', '$Maiden', '$DOB', '$Gender', '$Language', '$ID', '$Home_Tel', '$Work_Tel', '$Cell','$Fax_Tel', '$Email', '$Postal')";
$result = mysql_query($query);
$rows = mysql_affected_rows();

if ($rows < 1) echo "Error. The record has not been added to the database.";

else echo "$rows record has been added to the database.";




?>
</BODY>
</HTML>
avatar
Mac
Re: Project related
October 19, 2009 06:29PM
OK, here is a trick.

Language: PHP
$data = mysql_query("SELECT MAX ( id) AS id FROM home"); // get the max (or higest id) and give it the name id (it does not have to be the same) but then you have to correct for it further down in $row $row = mysql_fetch_array($data); $last_id_inserted= $row[id]; // or $last_id_inserted= $row[0];



Of course, I have purposefully not written the exact query for you smiling smiley I hate to mark myself smiling smiley

And this is not neccesarily the way you HAD to do it - you can do it anyway you want (stanimal is on the same trak, but his exact query statement may well differ from this). No problem - if it works, I'll accept it. We all have to start somewhere smiling smiley And this prac is as much about how you did it as how you coded it.

So, if you wonder about something and you cannot figure it out - then Google your question. You may have to open a few pages before you find the solution, but in it all you are learning. Of course - you are equally welcome to post your problem here - as you did. Hope this helps... and get takeaways.
Sorry, only registered users may post in this forum.

Click here to login