Php比较两个表值,每个表两个表示代码效率

I am a beginner in php, and so I need help understanding how to perform the task of comparing two tables which have a lot of records.

In user table I have:

id,
username,
phoneno,
city,
carddetails

and in the another table it has the fields:

id,
typeofthings,
typeofcard,
user_id(foreignkey).

I don't want to use a join in my query. I want to retrieeve all the user data with its typeofthings to show.

How can I do this in single foreach? please help me.thanks in advance

You should do this with a join.

Hands down. It will make your life much easier.

With join:

foreach($joined_data_row as $data) {
// do whatever you need to do.
 } 

without:

foreach($user_in_table_one as $user) { 
// another query - 
$users_data = ORM::for_table("user_data")->where("user_id", $user['id'])->find_one();
//do what you need to do. You now have $user from the first table and $user_data from the second.
}

Now, that is bad, bad, bad, bad. You will fail your class -- you will be fired from your job. Because you are making a query for each row returned Which is many times heavier of a load on the database! I just handed you a noose, don't hang yourself with it

With a join, however, you only make one database query -- which is much, much, much more efficient.

Now, since you're a beginner, I'll give you this tip: https://github.com/j4mie/idiorm

It will make your database functions much easier for you - including your join --

I know when I was a beginner, I hated MySQL until I came across that (We use propel, nowadays, however -- )