#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2008
    Posts
    3
    Rep Power
    0

    Red face Joining tables with php echo?


    Hi, I have looked through the forum but i'm still getting confused,

    I have a userdatabase and a confenquiry table. Userdatabase has a Userid which is imputed into the confenquiry along with other information when they enter a new enquiry. What i want to do is for each user to be able to display all their enquiries.

    I have a session in place so when i enter
    PHP Code:
    <? echo $userid?>
    it will come up with their userid. Therefore i thought i could write...

    PHP Code:
    SELECT enquirynum, startdate, enddate
    FROM confenquiry, userdatabase
    WHERE <? echo $userid;>? = useridconf
    However this does not work, can anyone suggest a different way for this to work?
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,679
    Rep Power
    4288
    it isn't clear from your query which columns belong to which table, so i will suggest that you make a habit always to fully qualify each column in any query involving more than one table

    however, in this case i'm guessing that you don't even need any of the columns from the "userdatabase" table

    Code:
    SELECT enquirynum, startdate, enddate 
      FROM confenquiry
     WHERE <? echo $userid; ?> = useridconf
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2008
    Posts
    3
    Rep Power
    0
    Hi,

    It doesnt like me putting in the php into the mysql string. I get the following error:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= useridconf' at line 1
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,679
    Rep Power
    4288
    this is no longer a mysql problem, this is a php problem

    run your query outside of php and you will see
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  8. #5
  9. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    618
    Rep Power
    15
    shouldn't the query be
    Code:
    SELECT enquirynum, startdate, enddate 
      FROM confenquiry
     WHERE $userid = useridconf
    without the <? echo ?> = around the variable?

    Comments on this post

    • requinix agrees

IMN logo majestic logo threadwatch logo seochat tools logo