Please can anyone help wth this. I want to be able to join the following queries so there is just one query to delete the course and associations with it. It works fine in two seperate queries, just wanted to know if I could do it in one?
$query1 = mysql_query("DELETE FROM course WHERE cid = '$cid' "
$query2 = mysql_query("DELETE FROM course_student WHERE cid = '$cid' "
Tried writing it a couple of different ways but alas.....nothing works.
Cool, thanks Mac. It is weird because writing it the longer way works fine - the course gets deleted and I get a happy message saying "Course deleted successfully".
Writing it the way below doesn't delete the course. It does give me a happy message though saying "the course has been deleted successfully" but when I actually check the list of courses - the course hasn't been deleted.
$query1 = mysql_query("DELETE course, course_student FROM course, course_student WHERE course.cid = '$cid' AND course_student.cid = '$cid' "
Any Ideas, otherwise I'll just keep it the simple way!
I understand what you mean by saying you want to use single query but if it works fine the longer yet simpler method use that. Try refreshing your page or Ctrl + Refresh. Your browser might be caching(Cache) so therefore the updated databse isn't showing.
Oh and i was wondering something. Deleting the course from the course and course student tables. The course_student associates the student with a course. If you delete a course from there the student or students already registered for that course will not be associated with any as the course itself will no longer be visible. So the student will be registered but not have a course.
i made it that you cannot remove a course if there are still student registered for the course. An error message is displayed when you try to delete the couse. This way I ensure that there will be no students without a course.
Registered: 14 years ago
Now you're starting to think..... good. We're starting with small steps here since we're focusing on the coding part.
Have a look here http://www.geekgirls.com/databases_from_scratch_3.htm
How would you have changed the current db structure??? Or would you have not? Does it depend on what you want, i.e. if you want to keep a history of student registration, how can the db be designed better?
I added that as well where the admin cannot delete a course if the course has been registered for. Good work JwV
I actually enjoyed working with this database structure. 3 tables linked by a common table (Course_Student). It was a bit challenging and fun. To make it much more simpler would have been to add the course the student registered for into the student table as well.
To keep a histroy of student registrations, another table called student_history for example could be used. Every student that registeres for a course would be added here as well as the course. This table will not be dependent on any other so data will not be lost if deleted elsewhere. OR say from some reason the admin has to delete a course, the student details are added to another table which keeps a record that he/she actually did register.
What i would like to have had with the student table is student numbers that are generated instead of using single digits from auto_increment as the student number. The id field(auto_increment) could have been used to generate a user id in the table but student number could be generated as below.
//returns 8 digit random number.
Registered: 14 years ago
> To make it much more simpler would have been to add the course the student registered for into the student table as well.
Student table must just have student info. course table just course info. The a table to join information. That's good db design (for starters). How you setup and use student_course db can change (e.g. use course name instead of course id)
I have my tables joined at the moment. I never liked it before(Joining tables) but when doing it here was fun and interesting to see the results. I prefer using an id or code wen parsing throught url(.php?id=). I like it in that way because i can manually input it incase i want to access something quickly. If i use example the course name i would have to each time enter the full name instead of a code if i wanted to enter it manually.
O and mac, could we make it that the student can edit his/her details as well. Maybe they made a mistake in their name etc or is it up to us.
thanks for the cool link Mac, looks like a good article.
But what if we have to delete a course that students are already registered for? Perhaps there are no lecturers or perhaps it was a new course and not enough students regsitered for the course? Now we have to delete the course and let students know that they will be refunded etc etc.
Perhaps the error message should give you a choice to delete the course if necessary despite any current registrations.
Once I get the basics down I might try doing this as the project has taken me forever thus far! But it is still exciting though when something finally works!!!
Yeah thanks but to use post or get everytime ill need to use a form each time to state post or get. Like this i'm sending information without a form. But ill do some research about other methods and see what happens.
With passing values from page to page one can use a session or a cookie.
When deleting a course you could link any student registered for that course to a "special course" called Deleted-couse and link that cid to the student. the cid for this special course could be 999999.
Prac is nearly there. Busy writing the update student and delete student pages and then I need to finish the report, then I am done.Then starts the testing, and adding the bells and whistles.
regarding sessions. I am using sessions thru out my prac. Each page starts with session_start(); then to load data into the session I use $_SESSION['init'] = $init; and to extract it I use $frm_init = $_SESSION['init'];. See chapter 5 (I think) in the masterskill manual for more info. All info I need is stored there. No hidden fields in forms or passing info from page to page. For some info I do use forms (POST and GET). Just remember to pass the session id from page to page. Hope this helps.
Mac >> Thanks for the info. I am passing the session id through out the prac. I am leaving it in, since everything is working. Will remove it later and see how it works. I hope that leaving it in will no count against me???
MuhammadA >> Hi there. Hope you are well. I finished my prac late last night.
Now just need to do some testing and see if everything works. Oh Yeah!!! Finished at last.
To all still busy with development - good luck to you all.