I need some advice how to get the next value of a row with while loop in php-mssql.
My code:
JavaScript
x
<?php
require 'db.php';
$result = "SELECT article_id, article_name, pic_link, group, price, ean
FROM artic";
$stmt = sqlsrv_query( $conn, $result );
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC) ) {
echo '<p><img src="' .$row[2] . '"/></p>
<div class="stats-container">
<span class="product_price">' .$row[4].'</span>
<span class="product_name"> ' .$row[1].' </span>
I am always getting the same product as you can see on the attached pic.
Advertisement
Answer
Don’t find real problem with the code provided. All “fetch” functions from php are intended to retrieve the next available row:
https://www.php.net/manual/en/function.sqlsrv-fetch-array.php
Maybe you are doing something with $row assignment later ($row = something instead $row == something).
if the entire loop is:
JavaScript
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC) ) {
echo '<p><img src="' .$row[2] . '"/></p>
<div class="stats-container">
<span class="product_price">' .$row[4].'</span>
<span class="product_name"> ' .$row[1].' </span>';
}
it should work fine.