How do I check 2 mysql tables at the same time?

1
$sql = "SELECT * FROM 'zzzz_1_post' WHERE POST_autor=1;

but I also want to get

$sql = "SELECT * FROM 'zzzz_0_post' WHERE POST_autor=0;

I'm doing it in a while, but I do not know how to combine the 2 tables at once.

My tables:

while($row = $resultado->fetch_assoc()) {//COMPROBAR POST
    $AMIGO_USUARIO_RED = $row['FRIEND_usuario'];
     $sql = "SELECT * FROM 'zzzz_".$row['FRIEND_usuario']."_post' WHERE POST_autor=".$row['FRIEND_usuario'];
    $resultado = $mysqli->query($sql);
    if(!$resultado = $mysqli->query($sql)) {
        echo "La consulta falló ";
        echo "Error: Lo sentimos, error a al conectarse, reinicie la pagina.";
        echo "Query: " . $sql . "\n";
        echo "Errno: " . $mysqli->errno . "\n";
        echo "Error: " . $mysqli->error . "\n";
        exit;
    }

    while($row = $resultado->fetch_assoc()) {//MOSTRAR LOS POST
    ?>
        <article class="post_view_public">
          <div class="post_view_loading">
             <i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
                <span class="sr-only">Cargando...</span>
          </div>
           <script type="text/javascript">
               function ocultar(){
                document.getElementById('post_view_loading').classList.add = "mostrar_loading_post" ;
                document.getElementById('post_view_public').classList.add = "ocultar_objetos";
                }
            </script>

            <div id="post_view_public">
            <div class="up">
            <?php
                    $sql2 = "SELECT * FROM 'a_redcdark_social' WHERE id_usuarios=".$AMIGO_USUARIO_RED;
                    $resultado2 = $mysqli->query($sql2);
                    if(!$resultado2 = $mysqli->query($sql2)) {
                        echo "La consulta falló ";
                        echo "Error: Lo sentimos, error a al conectarse, reinicie la pagina.";
                        echo "Query: " . $sql . "\n";
                        echo "Errno: " . $mysqli->errno . "\n";
                        echo "Error: " . $mysqli->error . "\n";
                        exit;
                    }

                    // No hay datos en esa consulta
                    if ($resultado2->num_rows === 0) {
                        echo "No Tienes amigos agregadoss";
                    }

                     while($row2 = $resultado2->fetch_assoc()) {

                         ?>
                <a href="?page=profile&id=<?php echo $row2['id_usuarios'];?>">
                    <img src="<?php echo $row2['RED_imagen_perfil'];?>" alt="user">
                    <h3><?php echo $row2['RED_nombre']; ?> <?php echo $row2['RED_apellido']; ?></h3>
                </a>

                <?php
                     }
                ?>
                <i class="fa fa-ellipsis-h"></i>
            </div>

            <div class="center" style="background:<?php echo $row['POST_background']?>">
        <?php

        if($row['POST_imagen'] == ""){
            echo $row['POST_texto'];
        }else{
            echo $row['POST_texto'];
            ?>

            <div class="imagen"><img src="<?php echo $row['POST_imagen'];?>" alt=""></div>
        <?php
        }
        ?>
            </div>
            <div class="downcent">
               <i class="fa fa-thumbs-o-up"> Like</i>
                <i class="fa fa-globe"></i>
                <i class="fa fa-ellipsis-v"></i>
            </div>
            <div class="down">
                <img class="comentuser" src="images/example/myuser.jpg" alt=""><span class="info">Usuario</span>

                <input type="text" placeholder="Comenta esta publicación">

                <i class="fa fa-smile-o"></i>
                <i>:v</i>
                <i class="fa fa-camera"></i>
                <i class="fa fa-ellipsis-v"></i>
            </div>
            </div>
            <script type="text/javascript">
               function mostrar(){
                    document.getElementById('post_view_loading').classList.remove = "mostrar_loading_post" ;
                   document.getElementById('post_view_loading').classList.add = "ocultar_objetos" ;
                   document.getElementById('post_view_public').classList.remove = "ocultar_objetos";
                    document.getElementById('post_view_public').classList.add = "mostrar_objetos";


                }
            </script>
        </article>
            <?php
    }

}//fin while 1

I want you to show the tables of the users (2)

    
asked by Cris GO 27.05.2018 в 03:22
source

2 answers

2

the only thing that can help you is an inner join as in the following sentences

SELECT * FROM 'zzzz_0_post' INNER JOIN zzzz_1_post

and in the php code in the view you have to place zzzz_0_post.POST_autor y zzzz_1_post.POST_autor to print the two data

    
answered by 27.05.2018 / 03:51
source
1

In this case you want to join two tables that have the same fields, so you must use the SQL UNION command, this joins the tables by adding one below the other
SELECT * FROM zzzz_0_post UNION SELECT * FROM zzzz_1_post ;

    
answered by 27.05.2018 в 04:22