Can someone tell me how to do it right? I tried on the principle of zar.name_zar and products.user, but unfortunately there are duplicate entries on this principle. To be clear, I need to output a list from products with a match from zar: $ resultA is the products table and resultB is the zar table.

if($resultA['ID'] == $resultB['id_zar']){$oplata = $resultB['price_zar'];} else{$oplata = "Не оплачено";} 

Here is the full code:

 mysql_query("SET NAMES utf8"); $sqlA = mysql_query("SELECT * FROM `products` WHERE user LIKE '%".$rname."%' ORDER BY ID DESC", $link); $sqlB = mysql_query("SELECT * FROM `zar` WHERE name_zar LIKE '%".$rname."%' ", $link); $resultA=mysql_fetch_array($sqlA); $resultB=mysql_fetch_array($sqlB); while ($resultA .$resultB) { if($resultA['ID'] == $resultB['id_zar']){$oplata = $resultB['price_zar'];} else{$oplata = "Не оплачено";} $oplata; echo '<tr>'. '<td><a href="/id.php?red_id='.$result['ID'].'"><i class="fa fa-file-text"></i></a></td>'. '<td>'.$result['ID'].''. '<td>'.$result['data'].'</td>'. '<td>'.$result['Tech'].'</td>'. '<td>'.$result['status'].'</td>'. '<td>'.$result['end'].'</td>'. '<td>'.$oplata.'</td>'. '</tr>' ; } 

    1 answer 1

    Combine your requests into one

     $sql = mysql_query(" SELECT * FROM `products` AS `p` LEFT OUTER JOIN `zar` AS `z` ON z.id_zar = p.ID WHERE p.user LIKE '%".$rname."%' ORDER BY p.ID DESC"); while ($result = mysql_fetch_array($sql, MYSQL_ASSOC)) { echo '<tr>'. '<td> <a href="/id.php?red_id='.$result['ID'].'"> <i class="fa fa-file-text"></i> </a> </td>'. '<td>'.$result['ID'].''. '<td>'.$result['data'].'</td>'. '<td>'.$result['Tech'].'</td>'. '<td>'.$result['status'].'</td>'. '<td>'.$result['end'].'</td>'. '<td>'.$result['price_zar'].'</td>'. '</tr>'; } 
    • It does not display correctly in order displaying price_zar and duplicate records, as well as it was said that it was already being done so .. - Victor Muravyov
    • @Viktor Muraviev updated the request. Redistribution link on id = id_zar - Evgeny Nikolaev
    • With such a request, the output is not the entire list of products with the participation of a specific user, but only if there is a record in zar. Such is the sadness that the whole list is needed - Victor Muravyov
    • @Viktor Muravyev, in other words, in the zar table there may be no information for the products table. right? - Evgeny Nikolaev