简体   繁体   中英

mysqli - php - returning all results from multiple tables

There is actually alot of answers for questions like that. But everything I found around here was to Join two tables with "like" values. But that isn't what I need.

I want to query two tables , that is almost exactly the same but with different values inside of it.

tbl_one and tbl_two (exemple names) has " id, title, date, content " its just the same. But inside of tbl_one has differente values of tbl_two .

And then, it's time to query. I could make two queries calling for tbl_one and after tbl_two , but it means that I'll have to print in different " whiles " and I don't want this. I need to print the results in only one "while", so I thought about one query to result from different tables, is that a way to do this?

For make it straight, I need to print the results in a while like this:

while($row = $result->fetch_array()) {
// my results printed
}

Where $result is the result from the query from the two previous tables.

I tried... "select * from tbl_one, tbl_two". Life would be a lot easier if this works.

Use union all to combine your queries ie

select * from tbl_one
union all select * from tbl_two

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM