By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Retrieve other database table's data

P: 24
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.
Jul 14 '07 #1
Share this Question
Share on Google+
5 Replies


mwasif
Expert 100+
P: 801
You have to query the database using mysql_query().
Jul 14 '07 #2

P: 24
Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT outletid, customerid, userid FROM customer, users
  2. WHERE users.outletid = reservation.outletid, customer.customerid = reservation.customerid, users.userid = reservation.userid";
  3. $result = mysql_query($sql);        
  4. $row = mysql_fetch_array($result); 
[Please use CODE tags when posting source code. Thanks! --pbmods]

you mean something like this?
Jul 14 '07 #3

mwasif
Expert 100+
P: 801
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.outletid, customer.customerid = reservation.customerid, users.userid = reservation.userid
WHERE users.userid = 123";[/PHP]
Jul 14 '07 #4

P: 24
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.outletid, customer.customerid = reservation.customerid, users.userid = reservation.userid
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

Expand|Select|Wrap|Line Numbers
  1. userid = $_GET['userid'];
  2.  
  3. $sql = "SELECT outletid, customerid, userid FROM customer, users
  4. WHERE users.outletid = reservation.outletid, customer.customerid = reservation.customerid, users.userid = reservation.userid
  5. WHERE users.userid = $userid"; 
Then how about customerid and outletid, do i have to include it in my WHERE clause?
Jul 14 '07 #5

mwasif
Expert 100+
P: 801
Did you try this query?
Jul 14 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.