0

heloo everyone, i am new to mysql and php. here i am diplaying my data by joining 3 tables.what this query is doing

1) displaying course name
2) displaying subject name
3) displaying status if any

there are three statuses (applied, accepted, rejected)

what i want to display is
1) course name
2)subject name
3)donot display the status if is is accepted.

after putting condition of != in SELECT query it doesnot show any accepted status but it doesnot remove the whole row instead its showing the whole row with no status and a blank space where it was showing accepted
how i can solve this problem,, hope i explained my question clearly any kind of help will be appreciated, thanx in advance :) here's my code

$result = mysql_query("SELECT courses.id AS cid, courses.title, courses.subjectsid, subjects.id AS sid, subjects.subjectname,  requestrecord.status
FROM courses JOIN subjects ON courses.subjectsid = subjects.id 
LEFT JOIN requestrecord 
ON courses.id = requestrecord.coursesid AND requestrecord.accountsid=".$_SESSION['id']." AND requestrecord.status!='accepted' ");
                                                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^      
3
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by urtrivedi
0

@Riu 2009

after putting condition of != in SELECT query it doesnot show any accepted status but it doesnot remove the whole row instead its showing the whole row with no status and a blank space where it was showing acceptedhow i can solve this problem,, hope i explained my question clearly any kind of help will be appreciated, thanx in advance :) here's my code

Did you create a table called 'status'? I think the reason why it didn't appear is because you didn't create a table called status.

Your status table should have these: applied, accepted, rejected

and when you run the query it will show one of these applied, accepted, rejected

0

i have created the table requestrecord and i have a column in that tble called status

1
$result = mysql_query("SELECT courses.id AS cid, courses.title, courses.subjectsid, subjects.id AS sid, subjects.subjectname,  requestrecord.status
FROM courses JOIN subjects ON courses.subjectsid = subjects.id 
LEFT JOIN requestrecord 
ON courses.id = requestrecord.coursesid AND requestrecord.accountsid=".$_SESSION['id']." 

WHERE requestrecord.status!='accepted' ");


                                                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^      

I have replaced AND with WHERE in last line, if you put AND, it will become part of your left join condition, to filter record, you must give condition in WHERE clause.

Edited by urtrivedi

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.