How to display the result of an Inner Join for the user?

0

I have three tables and I want to put them together and display them to the user, how can I do this using the WordPress functions?

INSERT THE DATA ON THE BANK:

function cadastra_experiencia($nome, $email, $experiencia){          //INSERE OS DADOS NO BANCO
     global $wpdb;

    $table = 'experiencia';

    $data = array(
      'nome' => $nome,
      'email' => $email,
      'exp' => $experiencia,
    );

    $updated = $wpdb->insert( $table, $data );

    if ( ! $updated ) {
      $wpbb->print_error();
    }
}

function cadastra_alturapesotipo($altura, $peso, $estilo){
//INSERE OS DADOS NO BANCO
     global $wpdb;

    $table = 'alturapesoestilo';

    $data = array(
      'altura' => $altura,
      'peso' => $peso,
      'estilo' => $estilo,
    );

    $updated = $wpdb->insert( $table, $data );

    if ( ! $updated ) {
      $wpbb->print_error();
    }
}

BANK:

CREATE TABLE EXPERIENCIA(
     exp_pri INT NOT NULL AUTO_INCREMENT,
     nome VARCHAR(150),
     email VARCHAR(50),
     exp VARCHAR(100),
     PRIMARY KEY(exp_pri)
);

CREATE TABLE PRANCHA(
    prancha_pri INT NOT NULL AUTO_INCREMENT,
    tamanho_prancha VARCHAR(8),
    meio_prancha VARCHAR(2),
    litragem_prancha VARCHAR(3),
    PRIMARY KEY (prancha_pri)
);

CREATE TABLE ALTURAPESOESTILO(
    idAltPes INT NOT NULL AUTO_INCREMENT,
    idExp INT,
    idPrancha INT,
    altura VARCHAR(4),
    peso VARCHAR(3),
    estilo VARCHAR(15),
    primary key (idAltPes),
    constraint fk_idExp foreign key (idExp) references EXPERIENCIA (exp_pri),
    constraint fk_idPrancha foreign key (idPrancha) references PRANCHA (prancha_pri)
 );

INNER JOIN:

SELECT EXP.exp,
       AEP.altura,
       AEP.peso,
       AEP.estilo,
       PRAN.tamanho_prancha,
       PRAN.meio_prancha,
       PRAN.litragem_prancha
FROM EXPERIENCIA AS EXP
    INNER JOIN ALTURAPESOESTILO AS AEP ON
    (EXP.exp_pri = AEP.idAltPes)
    INNER JOIN PRANCHA AS PRAN ON
    (PRAN.prancha_pri = AEP.idAltPes)

I put it in SQLFiddle for a better view: link

I want to display this inner join to the user (text, alert, modal), any example / path how to do this is welcome.

I took a look at the WordPress Codex, but without much success.

    
asked by anonymous 13.06.2016 / 20:14

1 answer

0

You're using $wpdb->insert , I do not know if you know but the wpdb class is easy to inject an attack on SQL because it interprets some functions of its own class as input, and could end up damaging your database of data.

For a better understanding, read the Wordpress documentation on the subject:

link

Now talking about your problem, have you tried using fetchAll() ? It returns an array containing all the rows in the result set and for inner join this works perfectly.

There are two functions related to fetching result lines. fetchAll() gets all rows at once. And fetch() gets row by line with each call.

But I believe you will use the fetchAll() function to get all the results at once because it is most convenient when working with inner joins .

Take a look at his documentation. With this command you can run very easily and show the result to the user.

fetchAll () documentation: link .

Fetch () documentation: link

    
13.06.2016 / 20:29