How do i write this as a join?

4 replies
I need to write this as a "JOIN", how do I do it?

("select * from c_projects where projects_id=$id AND active=1 AND item in (select item from cl_purchase where cemail='$_SESSION[member_username]' AND active > 0 AND item in permissions =$id)")

Thanks for your help!
#join #write
  • Profile picture of the author esoomllub
    I started writing something, but then realized I was probably not thinking of your DB right. Can you describe it a little?
    Signature
    {{ DiscussionBoard.errors[8292989].message }}
    • Profile picture of the author kevbo22
      This query runs just fine:
      ("select * from c_projects where projects_id=$id AND active=1 AND item in (select item from cl_purchase where cemail='$_SESSION[member_username]' AND active > 0 )")

      But I also need to make the association with the table permissions and column item:
      AND item in permissions =$id

      I have no clue how to write this out as a join query

      Thanks for the help
      Signature

      The best path to prosperity is free market capitalism!

      {{ DiscussionBoard.errors[8293098].message }}
      • Profile picture of the author kevbo22
        solved:
        $sql="select *
        from c_projects
        join c_purchase on c_projects.item = c_purchase.item
        join permissions on c_projects.item = permissions.item
        where c_purchase.cemail = '{$_SESSION[member_username]}'
        and c_purchase.active > 0
        and permissions.item = '{$id}'";
        Signature

        The best path to prosperity is free market capitalism!

        {{ DiscussionBoard.errors[8293155].message }}
  • Profile picture of the author Andrew H
    Your code is wide open to sql injection. Read this please: mysql - How to prevent SQL injection in PHP? - Stack Overflow

    Guess what would happen if I did this?

    Code:
     $ id = "'somevar'; DROP TABLE c_projects;";
    Signature
    "You shouldn't come here and set yourself up as the resident wizard of oz."
    {{ DiscussionBoard.errors[8293630].message }}

Trending Topics