0

Hi i am new to zend and mysql so please ignore if this is a silly ques. i have two tabels: users and user_cars. Now the user_cars table contains same user with multiple cars. i.e. if a user has three different cars, then the user_cars table contains three entries for that user. Now i want to select a particular user from user_cars table. The userid is given to me. can anyone please tell me how to do that.

    users: 
    userid, username, password, fname, lname               // columns

    user_cars:
    id, userid, car_name, purchase_date                    // columns

so i have a userid and want to select all the rows from user_cars with the given userid. can anyone please tell me how to do this.

Naphstor
  • 2,356
  • 7
  • 35
  • 53

2 Answers2

0

select a.userid, a.username, a.fname, a.lname, b.car_name, b.purchase_date
from users a, user_cars b
where a.userid = b.userit and a.userid = 1

this selects username, first and last name, and car name and purchase date for userid 1

Andrey
  • 1,808
  • 1
  • 16
  • 28
0
$db     = Zend_Db_Table::getDefaultAdapter();
$query  = "SELECtT * FROM user_cars WHERE userid = " . (int)$userId;

$cars   $db->fetchAll($query);
// You have all the user's cars in the $cars var

But what you're asking is really not clear so maybe it's not this

yokoloko
  • 2,820
  • 3
  • 20
  • 27