Comparison of Mysql data from two different databases - PHP

Asked

Viewed 625 times

1

My web application should access two different databases on different servers, put the column of the two databases on the screen and compare the result between them.

However, it only returns the value of one of the banks and the other it returns everything zero as the image. inserir a descrição da imagem aqui

   while ($line = mysql_fetch_array($table_primal1) && $lineup = mysql_fetch_array($table_primal2) ) {

   $convert2 = (float) $line['campo016'];
   $convertup = (float) $lineup['campo016'];       
if($convertup==$convert2){
    $compara = 'Correto';
    $printtr = 'trcorrect';
    $printtd = 'correct';
} else {
    $compara = 'Erro';
    $printtr = 'trerror';
    $printtd = 'error';
}

   echo'<tr class='.$printtr.'>';
   echo'<td class='.$printtd.'>'  .$line['papel'].  '</td>';
   echo'<td class='.$printtd.'>'  .$line['campo036'].  '</td>';
   echo'<td class='.$printtd.'>'  .$convert2.  '</td>';
   echo'<td class='.$printtd.'>'  .$convertup.  '</td>';
   echo'<td class='.$printtd.'>'  .$compara.  '</td>';     
   echo'</tr>';        

The code that should do this is basically that. I tried to put a while inside the other, but it just returns me the first result of the other column and dps repeats.

inserir a descrição da imagem aqui

Follow my Querys:

  $table_primal1 = mysql_query("SELECT * FROM quotes where origem='30' and papel like 'ZS_8' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZC_8' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZL_8' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZS_7' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZC_7' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZL_7' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZS_9' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZC_9' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZL_9' AND campo012 >= '0' AND campo016 >='0' ORDER BY papel ASC",$conexao_ori30a);

  $table_primal2 = mysql_query("SELECT * FROM quotes where origem='30' and papel like 'ZS_8' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZC_8' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZL_8' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZS_7' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZC_7' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZL_7' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZS_9' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZC_9' AND campo012 >= '0' AND campo016 >='0' or origem='30' and papel like 'ZL_9' AND campo012 >= '0' AND campo016 >='0' ORDER BY papel ASC", $conexao_ori30b);
  • Cade mysql_query()?

  • The querys() seem right, also puts the mysql_connect():P

  • I updated with them

  • This connection I can not show, but I can guarantee that it is working perfectly, because I had managed to print the two tables perfectly while they were separate

  • Okay, when you call the mysql_connect() informs 4 arguments? the last being true? example: mysql_connect('localhost', 'usuario', 'senha', true);

  • No, I call $login = mysql_connect('localhost', 'user', 'password') and dps call mysql_select_db('bank', $login)

  • Raisin true on both calls from mysql_connect(), should solve the problem. I imagine that the server, user and password are the same.

  • As I said in the question, the tables are on separate servers. ?

  • Even passing the true didn’t work?

  • I keep the mysql_select_database right?

  • Yes, let mysql_select_database normal.

  • That was the first example I gave :(

Show 7 more comments

1 answer

0


I ended up discovering the answer unintentionally kkk, I will post here if eventually someone has the same problem.

Instead of putting $line_up= mysql_fetch_array($table_primal2) in some while, I simply played it along with the values that would be obtained by the table and it worked.

while ($line = mysql_fetch_array($table_primal1) ) {
    $line_up= mysql_fetch_array($table_primal2)

$convert2 = (float) $line['campo016'];
$convertup = (float) $lineup['campo016'];       
if($convertup==$convert2){
$compara = 'Correto';
$printtr = 'trcorrect';
$printtd = 'correct';
} else {
$compara = 'Erro';
$printtr = 'trerror';
$printtd = 'error';
}

echo'<tr class='.$printtr.'>';
echo'<td class='.$printtd.'>'  .$line['papel'].  '</td>';
echo'<td class='.$printtd.'>'  .$line['campo036'].  '</td>';
echo'<td class='.$printtd.'>'  .$convert2.  '</td>';
echo'<td class='.$printtd.'>'  .$convertup.  '</td>';
echo'<td class='.$printtd.'>'  .$compara.  '</td>';     
echo'</tr>'; 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.