Show data from two different mysql databases on the same page

0

Good morning. I have that question, I have two tables, with 2 matches each, and I want to show on the same page the 4 matches that are in the different tables of the database. I use this to show my database:

		$sql="SELECT * from dpartidos";
		$result=mysqli_query($conexion,$sql);

		while($mostrar=mysqli_fetch_array($result)){
// Lo muestro con un echo y la variable $mostrar['partido1']

And the other two games that I want to show are in a table called "dpartidos2", and they have the same name: "partido3" and "partido4"

And with this example:

    $sql="SELECT partido1, partido2
FROM dpartidos
UNION
SELECT partido3, partido4
FROM dpartidos2 ";
    $result=mysqli_query($conexion,$sql);

    while($mostrar=mysqli_fetch_array($result)){

if ($quediaes=="Wed" && 0 <= $hora && $hora <= 10) {
    echo '<h3>No hay ningun partido en este momento</h3>';
}
else if ($quediaes=="Wed" && 11 <= $hora && $hora <= 12) {
  echo '<h3>Estás mirando: ' . $mostrar['partido1'] . '</h3>';
}

else if ($quediaes=="Wed" && 13 <= $hora && $hora <= 14) {
  echo '<h3>A continuacion: ' . $mostrar['partido1'] . '</h3>';
}
else if ($quediaes=="Wed" && 15 <= $hora && $hora <= 17 ) {
  echo '<h3>Estás mirando: ' . $mostrar['partido3'] . '</h3>';
}
else if ($quediaes=="Wed" && 16 <= $hora && $hora <= 23) {
    echo '<h3>No hay ningun partido en este momento</h3>';
}
}

He does not play me and he puts me twice "You're watching"

    
asked by MatiPHP 27.06.2018 в 19:39
source

1 answer

0

You can use UNION to join the results of the two SELECT in the same answer

SELECT *
FROM dpartidos
[WHERE conditions]
UNION ALL
SELECT *
FROM dpartido2
[WHERE conditions]

Now as a clarification, the SELECT should return the same number of columns and the data type of the same should be the same, I guess it is like that, if you do not give me more data and we look for another solution

    
answered by 27.06.2018 в 20:48