For some reason, my PHP displays only the first value from the database, how to solve it?
$mysql = mysqli_connect($c['host'], $c['user'], $c['pass'], $c['db']); $sql=mysqli_query($mysql,"SELECT * FROM dle_users WHERE user_id = '".$_COOKIE['dle_user_id']."'"); while($row=mysqli_fetch_array($sql)){ $pro = mysqli_connect($c['host'], $c['user'], $c['pass'], $c['db']); $prod=mysqli_query($pro, "SELECT * FROM dle_products "); while($pdo = mysqli_fetch_array($prod, MYSQLI_BOTH)){ if(file_exists('buy/mc/'.$pdo['item_id'].'.png')){ $img = 'buy/mc/'.$pdo['item_id'].'.png'; } else { $img = 'buy/mc/unknown.png'; } $image = '<img src="'.$img.'" alt="'.$pdo['name'].'">'; echo' <i class="fa fa-info" aria-hidden="true" title="'.$pdo['description'].'"></i> '.$pdo['name'].'<br /> '.$image.'<br /> '.$pdo['price'].' '.$valet.' за '.$pdo['amount'].' шт'; } mysqli_close($pro); } mysqli_close($mysql); The code seems to be correct, but all the same it displays only the first value from the database
mysqli_query($mysql,"SELECT * FROM dle_users WHERE user_id = '".$_COOKIE['dle_user_id']."'");You can not substitute the values that came from the user directly to the request. It is necessary to use prepared queries.$pro = mysqli_connect($c['host'], $c['user'], $c['pass'], $c['db']);to make the second connection in this case is senseless and merciless.while($row=mysqli_fetch_array($sql)){value of$rownot used anywhere. Check for the existence of the user is carried out a little differently.mysqli_close($pro);It is not necessary to close the connection (except in rare cases). - ArchDemonmysqli_num_rows($prod);value ofmysqli_num_rows($prod);. What does it matter? - ArchDemon