PHP collect and combine different data from two tables

David Kristiansen

I have these two tables which I'm trying to make an output of. The first one **USERS** stores all information about a user, including an unique ID (androidID). The second one gets input based on number of laps a user has taken, and will make one row pr lap.

What I'm trying to do is to output the last entry of a given androidID in **ROUNDS**, whith the corresponding name etc. from **USERS**

_____________________        _________________________
|    **USERS**      |        |      **ROUNDS**       |
---------------------        -------------------------
| NAME              |        | ID(unique)            |
| LASTNAME          |        | TIME                  |
| androidID(unique) | <----> | androidID(NOT unique) |
| ...               |        | ROUNDS                |

This is how I'm quering the server

$result_users = $con->query(
    "SELECT * FROM users"
);

$result_rounds = $con->query(
    "SELECT * FROM Rounds ORDER BY laps desc"
);

I tried to numerous combination of the following. With no luck. My PHP skills is not the best, I'm afraid.

foreach ($result_users as $row_users) {
    foreach ($result_rounds as $row_rounds) {
         if($row_users['androidID'] == $row_rounds['androidID'] {
             // Do some wizzardy
         }
    }
}

I have really hit a wall trying to connect the tables.

kayleighsdaddy

This would be the sql statement you want in your query.

SELECT * FROM `**USERS**` LEFT JOIN `**ROUNDS**`ON `**USERS**`.`androidID` = `**rounds**`.`androidID` ORDER BY `laps` desc 0,1;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Combine data from two different junction tables

From Dev

Combine data from two different junction tables

From Dev

Combine rows from two tables with different columns?

From Dev

Echo data from two different mysql tables using php

From Dev

Selecting data from two different tables of the same database in PHP/ MYSQL

From Dev

How to combine data from two independent tables?

From Dev

Combine tables with different data

From Dev

Search data from two different tables that two tables in different databases

From Dev

Collect data from 2 different tables, following conditions

From Dev

Combine two queries from different tables and sort by a common column?

From Dev

Combine two queries from different tables and sort by a common column?

From Dev

PHP Select * from two different tables?

From Dev

How to fetch data from two different tables

From Dev

MySQL Combine data from two tables with table name

From Dev

MySQL Combine data from two tables with table name

From Dev

PHP reading data from different tables

From Dev

Retrieve data from two tables php

From Dev

Display data from two tables - PHP mySQL

From Dev

Combine results of two tables having different structure

From Dev

Python: How to combine specific columns from two different data frames

From Dev

How to combine and summarize R data.table rows values from different tables of different sizes?

From Dev

Displaying values from two different tables inside dropdownlist using php

From Dev

Matching two columns from different tables - MySQL PHP

From Dev

Retrieve data from two different tables and output into a column value

From Dev

Insert data in two different tables from single Controller in Yii

From Dev

Displaying retrieved data from GAE datastore in two different html tables

From Dev

fetch data from two different tables on same textbox changed event

From Dev

Sum data from two tables with different number of rows

From Dev

how do i get hierarchy of data from two different tables?

Related Related

  1. 1

    Combine data from two different junction tables

  2. 2

    Combine data from two different junction tables

  3. 3

    Combine rows from two tables with different columns?

  4. 4

    Echo data from two different mysql tables using php

  5. 5

    Selecting data from two different tables of the same database in PHP/ MYSQL

  6. 6

    How to combine data from two independent tables?

  7. 7

    Combine tables with different data

  8. 8

    Search data from two different tables that two tables in different databases

  9. 9

    Collect data from 2 different tables, following conditions

  10. 10

    Combine two queries from different tables and sort by a common column?

  11. 11

    Combine two queries from different tables and sort by a common column?

  12. 12

    PHP Select * from two different tables?

  13. 13

    How to fetch data from two different tables

  14. 14

    MySQL Combine data from two tables with table name

  15. 15

    MySQL Combine data from two tables with table name

  16. 16

    PHP reading data from different tables

  17. 17

    Retrieve data from two tables php

  18. 18

    Display data from two tables - PHP mySQL

  19. 19

    Combine results of two tables having different structure

  20. 20

    Python: How to combine specific columns from two different data frames

  21. 21

    How to combine and summarize R data.table rows values from different tables of different sizes?

  22. 22

    Displaying values from two different tables inside dropdownlist using php

  23. 23

    Matching two columns from different tables - MySQL PHP

  24. 24

    Retrieve data from two different tables and output into a column value

  25. 25

    Insert data in two different tables from single Controller in Yii

  26. 26

    Displaying retrieved data from GAE datastore in two different html tables

  27. 27

    fetch data from two different tables on same textbox changed event

  28. 28

    Sum data from two tables with different number of rows

  29. 29

    how do i get hierarchy of data from two different tables?

HotTag

Archive