Retrieve other database table's data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fruityfreak
    New Member
    • Jun 2007
    • 24

    Retrieve other database table's data

    I would like to know how to I retrieve information from another database table...

    Instead of keying in manually, I would like to retrieve data directly from the logged in user row. For the user table, i have outletid in it.

    Outlet ID: <input type="text" name="outletid" > (Manually)
    Outlet ID: <?php echo $row['outletid']; ?> (Is this how it looks like if I want to retrieve data another table)

    I think it has got to do with join table but I'm not sure of how to do so.
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    You have to query the database using mysql_query().

    Comment

    • fruityfreak
      New Member
      • Jun 2007
      • 24

      #3
      [code=php]$sql = "SELECT outletid, customerid, userid FROM customer, users
      WHERE users.outletid = reservation.out letid, customer.custom erid = reservation.cus tomerid, users.userid = reservation.use rid";
      $result = mysql_query($sq l);
      $row = mysql_fetch_arr ay($result); [/code]

      [Please use CODE tags when posting source code. Thanks! --pbmods]

      you mean something like this?

      Comment

      • mwasif
        Recognized Expert Contributor
        • Jul 2006
        • 802

        #4
        yes, you are right. But you have to mention user id in the WHERE clause

        [PHP]$sql = "SELECT outletid, customerid, userid FROM customer, users
        WHERE users.outletid = reservation.out letid, customer.custom erid = reservation.cus tomerid, users.userid = reservation.use rid
        WHERE users.userid = 123";[/PHP]

        Comment

        • fruityfreak
          New Member
          • Jun 2007
          • 24

          #5
          Originally posted by mwasif
          yes, you are right. But you have to mention user id in the WHERE clause

          [PHP]$sql = "SELECT outletid, customerid, userid FROM customer, users
          WHERE users.outletid = reservation.out letid, customer.custom erid = reservation.cus tomerid, users.userid = reservation.use rid
          WHERE users.userid = 123";[/PHP]

          But my userid is a variable it'll change according to the logged in user's userid... so can i put it as

          [code=php]userid = $_GET['userid'];

          $sql = "SELECT outletid, customerid, userid FROM customer, users
          WHERE users.outletid = reservation.out letid, customer.custom erid = reservation.cus tomerid, users.userid = reservation.use rid
          WHERE users.userid = $userid"; [/code]

          Then how about customerid and outletid, do i have to include it in my WHERE clause?

          Comment

          • mwasif
            Recognized Expert Contributor
            • Jul 2006
            • 802

            #6
            Did you try this query?

            Comment

            Working...