Hey everyone, my problem is that Im trying to get variables to increment inside of a nested while loop that is displaying formatted MySQL results. Getting stuck on something this simple makes me feel a little ridiculous but I need to. Here is the code I have right now, but the for() loop isn’t incrementing the value of $i by 1 after each ind. product is displayed, just remains as a value of 1 for every iteration.
to shorten this up and make it easier i just included the query strings and the results im trying to pass, nothing else really matters.
[code=php]
$CartSQL = “SELECT * from tblCart Where CartSessionID = ‘” . $_SESSION[‘SessID’] . “‘”;
$rsCartSQL = mysql_query($CartSQL);
for($i = 1; $i < mysql_num_rows($rsCartSQL); $i++){
while($PrIDs = mysql_fetch_array($rsCartSQL)){
$sql = “SELECT * from tblProduct where PrID='” . $PrIDs[‘CartPrID’] . “‘”;
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
echo “<input type=’hidden’ name=’L_NAME$i’ value=’$row[PrDispName]’>”;
echo “<input type=’hidden’ name=’L_AMT$i’ value=’$row[PrPrice]’>”;
echo “<input type=’hidden’ name=’L_QTY$i’ value=’$PrIDs[CartPrQty]’>”;
echo “<input type=’hidden’ name=’L_DESC$i’ value=’$row[PrDesc]’>”;
echo ‘<tr><td width=”65%”><a href=”products.php?id=’ . $row[‘PrID’] . ‘”> ‘ . $row[‘PrDispName’] . ‘</a></td><td><img src=”‘ . $row[‘PrImage’] . ‘” alt=’ . $row[‘PrName’] . ‘” height=”50px” width=”50px”></td>’;
echo ‘<td>$’ . $row[‘PrPrice’] . ‘</td>’;
echo ‘<td>Qty:’ . $PrIDs[‘CartPrQty’] . ‘</td>’;
echo ‘<tr><td colspan=”4″><hr/></td></tr>’;
echo ‘</tr>’;
$total = $row[‘PrPrice’] * $PrIDs[‘CartPrQty’];
}
$_SESSION[‘total’] += $total;
}
}
as you can see im trying to increment for the hidden values, which eventually will be Name-Value pairs sent to a secure server for transaction, right now with this code they are being sent as
LNAME1
LNAME1
LDESC1
LDESC1
no incrementing.
thanks for any help guys, it’s appreciated.