Web Analytics Made Easy -
StatCounter Query 2 tables at the same time... i've googled all morning... - CodingForum

Announcement

Collapse
No announcement yet.

Query 2 tables at the same time... i've googled all morning...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Query 2 tables at the same time... i've googled all morning...

    I hope you guys can help... I've been googling all morning, but I just don't understand this whole multi-table query thing....

    I need it to return only todo lists where the logged in user(session) is assigned to a list and where that user is active (active to a list, not a specific task).

    Assignments

    Users

    Todo Lists

    Tasks for lists (ignore for this problem, placed just to see the data)

  • #2
    Not sure, but is this was your trying to do?

    PHP Code:
    $sql "SELECT * FROM users AS U, assignments AS A, todo AS To, tasks AS Ta WHERE U.id == A.id AND A.taskid == Ta.todoid"
    There's lot of google examples

    http://www.google.com/search?hl=en&q...es&btnG=Search

    Comment


    • #3
      Originally posted by ptmuldoon View Post
      Not sure, but is this was your trying to do?

      PHP Code:
      $sql "SELECT * FROM users AS U, assignments AS A, todo AS To, tasks AS Ta WHERE U.id == A.id AND A.taskid == Ta.todoid"
      There's lot of google examples

      http://www.google.com/search?hl=en&q...es&btnG=Search
      see I have no idea what the U, A tA stuff means so I have no idea on how to comprehend it. 99% of the "tutorials" I found had fake data or no data at all and didnt show the results... which I guess is how I learn :/
      Last edited by aaronl; Apr 13, 2009, 04:47 PM.

      Comment


      • #4
        See how you have the same field name todoid in both the Assignments and Tasks tables? In order to match those fields, you need something like tasks.todoid == assignments.todoid

        A common approach is to temporarily call your tables something else in query. So tasks AS Ta and assingments AS A.

        I would used one letter for all tables, but for you had two tables beginning with T. So it was tasks AS Ta and todo As To.

        Comment


        • #5
          Originally posted by ptmuldoon View Post
          See how you have the same field name todoid in both the Assignments and Tasks tables? In order to match those fields, you need something like tasks.todoid == assignments.todoid

          A common approach is to temporarily call your tables something else in query. So tasks AS Ta and assingments AS A.

          I would used one letter for all tables, but for you had two tables beginning with T. So it was tasks AS Ta and todo As To.
          ok that makes sense.... kinda... I tried to use what you gave, but it returned nothing... this is the statement that I thought would do it to begin with if it helps...

          Code:
          $query = "Select * from todo, assignments where assignments.userid = '%$_SESSION[myusernameid]%' and todo.id == assignments.todoid";
          Im not even sure if thats the right thing to get what I want... but it sounds right in my newbie brain :/

          Comment


          • #6
            well im a tard. lol the select statement that I listed below works (minus the == ) besides the fact that my session variable had % on either side of it from when I had teh great idea to search by username instead of the usernameid..... yea im an idiot, i know.... argh!

            Comment

            Working...
            X