i have a table link with a structure like this
spreader | host1 | host2 | host 3 | id | datetime |
---------------------------------
expl.com | 1 | 5 | 2
what.de | 1 | 5 | 2
expl.com | 1 | 2 | 3
what.de | 2 | 5 | 5
How to check if the last 2 entry with the same spreader have the same values in host1, host2, host3 ...
For this example it sould give me
- expl.com => host1 = 1
- what.de => host2 = 5
I maybe know a way but i would have to have 10 sql querys one for each host. Do you know a efficient way to do this in php after i just get the entire date from the database with just one query?
Well i got this now it fires out 10 mysql querys i would love to see how to make this better:
global $hosters;
global $filespreader_names;
foreach ( $filespreader_names as $filespreader ) {
$feedtable = feedback_tabelle_holen(" WHERE filespreader='$filespreader' ORDER BY aktualisiert DESC LIMIT 2");
//var_dump($feedtable);
foreach ( $hosters as $host ) {
if ( ( $feedtable[0][$host] == $feedtable[1][$host] ) && ( $feedtable[0][$host] != 0 ) ) {
echo "<br />$filespreader -> $host = " . $feedtable[0][$host];
}
}
}
the globals i get in are just arrays with all the spreaders and host names i need
You might be able to do an Inner Join to produce matching records. If the gloabals you get in are from another table an inner join will give you a recordset with all the matching records that you could manipulate from there but it would only be one query.
If this is TableA on the left and TableB on the right.
id name id name
-- ---- -- ----
1 Pirate 1 Rutabaga
2 Monkey 2 Pirate
3 Ninja 3 Darth Vader
4 Spaghetti 4 Ninja
SELECT * FROM TableA
INNER JOIN TableB
ON TableA.name = TableB.name
That query will result in rows of the matching data according to your query
id name id name
-- ---- -- ----
1 Pirate 2 Pirate
3 Ninja 4 Ninja
I don't know if that helps at all but I wasn't really clear on your structure and exactly what you wanted. If the globals are session variables and not stored in a table this answer probably won't help you.
If you want to use joins check out http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html