Welcome! Log In Create A New Profile

Advanced

linking table

Posted by 78042968 
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
linking table
April 18, 2013 02:17AM
Language: PHP
Mac. I think our tables must be linked like this.   (Course_student.cid)=(course.cid) (Course_student.sno)=(student.sno) This is how I did on my tables but the problem is that I can not view ';sno'; from the table ';student'; on the table(course_student). Where must I check the errors.

Sihle
Re: linking table
April 18, 2013 08:19AM
interesting

Please explain what you are trying to do. I think I know of a simplier way to do what I think you are trying to do. but I am not sure what you are trying to do.
avatar
Mac
Re: linking table
April 19, 2013 09:01AM
I am also lost? Use the table structures as it was provided - you cannot change that structure.
Re: linking table
April 19, 2013 09:13AM
Forgive me if I'm misunderstanding but do you mean this:

Language: PHP
WHERE course_student.cid = course.cid AND course_student.sno = student.sno
Re: linking table
May 01, 2013 01:27AM
77959132 NeoGek Wrote:
-------------------------------------------------------
> Forgive me if I'm misunderstanding but do you mean
> this:
>
>
Language: PHP
> WHERE course_student.cid = course.cid > AND course_student.sno = student.sno >

Yes that what I meant
Re: linking table
May 01, 2013 10:39AM
Are you trying to list all the courses on one page with the registered students underneath the respective course?

Like this:

Course A
Fernando Alonso
Kimi Raikonen

Course B
Seb Vettel
Mark Webber

Course C
Adrian Sutil
Jenson Button

I tried this and kept getting:

Course A
Fernando Alonso
Course A
Kimi Raikonen

etc.

Then I tried foreach-ing it...got a little confused and then realised that the tut letter says you can have the list.php be a list of Courses that each course links to the students registered to it...that is how I am reading it at the moment anyway smiling smiley
Re: linking table
May 01, 2013 02:09PM
@ 78042968 I'm confused me too you did not explain
how should your table list be like e.g ordered list or
unordered list so that s why Im people are confussed
and me too. try to exlain please.

78009855
Re: linking table
May 02, 2013 07:56AM
Solomzi - you shouldn't be told to sort your table or not, if you want your project to be userfreindly, you should know to apply those things.

and Mac did say you are Free to do what you think will make you project functional and userfriend. you are not limited in how you go about doing that, as long as its PHP, not too much of JavaScript and OOP, I am sure he wont panalise anyone for using JS or OOP, but you will not be getting marks for it, since this is a PHP course.
Re: linking table
May 05, 2013 11:00PM
ok I get you 77911997

78009855
Re: linking table
May 16, 2013 12:42PM
Hi guys,

This might be the worst question ever but how do i link course_student table to course and student table so as to get my sno, cid and year?

Please help, been coding for days cant even think straight!

Thanks in anticipation.

78026962 afojonny
avatar Re: linking table
May 16, 2013 02:16PM
I used Joins in mySQL to get data from 2 tables. The function below will display all the courses that a student is registered for. Somewhere on the forum I posted a link to a tutorial for SQL Joins, just can't find it.


Language: PHP
function getStudCrs($regStud){ conDB(); $sql = "SELECT b.cname FROM course_student a, course b WHERE a.sno = $regStud AND a.cid = b.cid ORDER BY b.cname"; $result = mysql_query($sql); while($selRows = mysql_fetch_array($result)){ echo $selRows[';cname';] . "<br>"; } mysql_close(); }




afojonny Wrote:
-------------------------------------------------------
> Hi guys,
>
> This might be the worst question ever but how do i
> link course_student table to course and student
> table so as to get my sno, cid and year?
>
> Please help, been coding for days cant even think
> straight!
>
> Thanks in anticipation.
Re: linking table
May 16, 2013 02:24PM
Thanks AlexB. So, the linking is done in phpMyAdmin and not with a text editor to save as .php...am i right?

78026962 afojonny
avatar Re: linking table
May 16, 2013 04:47PM
I did do the link in phpMyAdmin, but I am not sure if that had any impact on my SQL query. The website that I got the info from just said that a Join mashes different tables into one and then allows you to draw the information from that new table. Check with Mac on the linking in phpMyAdmin.

afojonny Wrote:
-------------------------------------------------------
> Thanks AlexB. So, the linking is done in
> phpMyAdmin and not with a text editor to save as
> .php...am i right?
avatar
Mac
Re: linking table
May 16, 2013 05:11PM
??? Linking in phpMyAdmin is what is known as stored procedures - way advanced stuff at this stage, and only recently available in MySQL

A join is somewhat advanced, and some people may crucify me for not pushing this... but I believe in developing logic first. You can always code better (after 13 years I discover new ways to code every day). This course is more about basics and logic. Small steps.

See this: http://www.w3schools.com/sql/sql_join.asp

You do not have to use joins. If you do, cool. Perhaps a mark extra, but you cannot fail using nested queries as here below

Language: PHP
sql query to find a row { I have the row Using this info, create another sql query that targets another table- this query is run within the bracket of the first query, but has it owns brackets get the info   } //close original bracket

So basically it is an issue of where you place the brackets...
Re: linking table
May 17, 2013 08:33AM
I have done this but I did not link tables. I first retrieved info from course_student, I then used a student number to get student info from a student table.

Language: PHP
SELECT * FROM course_student WHERE cid = $courseid ORDER BY sno ASC .... while($studentrow = mysql_fetch_array($studentresult, MYSQL_ASSOC)) { $sno = $studentrow[';sno';];   SELECT * FROM student WHERE sno = $sno ..... from here you can get what ever info you want from a student table.     }
Re: linking table
May 17, 2013 11:19AM
I have been on this course_student table since yesterday morning and my project has seem to come to a halt because of it. Slept late and i'm awake this early morning again to tackle the same issue but now, I GIVE UP and i need help!!!

Here's the code i came up with to get the auto increment from 'student' table and then insert to 'sno in course-student'.

Language: PHP
//========================= //INSERT DATA INTO DATABASE //========================= $sql = "INSERT INTO student(sname, init, fname, title, msname, dob, gen, lang, idno, telh, telw, cel, fax, email, address) VALUES (';$surname';, ';$initials';, ';$ffname';, ';$title';, ';$psurname';, ';$dob';, ';$gender';, ';$loc';, ';$idno';, ';$htel';, ';$wtel';, ';$cpnumber';, ';$fax';, ';$email';, ';$postadd';)"; $result = mysql_query($sql) or die (mysql_error());   //========================================= //GET AUTO INCREMENT FROM LAST INSERT TABLE //========================================= $student_id=mysql_insert_id();   $sql2 = "INSERT INTO course_student (sno, year) VALUES (';$student_id';, ';now()';"; $result2 = mysql_query($sql2) or die (mysql_error());   if (($result) && ($result2)) { echo "Registration successful."; } else { echo "There was a problem with the registration. Please try again"; } }

It just returns '000000s' into my course_student table in the database.

Please how do i deal with this so i don't waste the rest of the times on this.

I look forward to a positive answer. Thanks.

78026962 afojonny
Re: linking table
May 17, 2013 11:26AM
Mac,

I have tried to read up the tutorial from the w3schools. Learnt a thing or two but it didn't help in solving my misery. May-be i didn't get what you're trying to point out there. Please help in this regard.

78026962 afojonny
Re: linking table
May 17, 2013 12:41PM
echo $student_id and see what you get;
Re: linking table
May 17, 2013 12:53PM
I get the right id.

But it doesn't print in the course_student table, rather it just adds some Zeros to all the rows.

78026962 afojonny
avatar
Mac
Re: linking table
May 20, 2013 08:58AM
What field type did you use for sno in sutuent_course? Change it to BIGINT
Sorry, only registered users may post in this forum.

Click here to login