I am trying to write a foreach loop and I am running into a problem with my foreach loop. You would think after doing so many of them I would know them back and forth by now. Anyway I extract an array from by DB with 9 entries such as account number, order number account name etc.
When I try to display them using a foreach loop, I get duplicate output because it is using the numeric key and the column named key such as below:
0 = 25
id = 25
1 = 434891
order_num = 434891
2 = "CUP,FOAM,8 OZ"
description = "CUP,FOAM,8 OZ"
I have run into this issue previously, but only when the $results=mysql_fetch_array returned just 1 row. Here there are multiple rows in the $results array.
Here is the actual code:
if ($_GET[acct_num]){
$sql = "SELECT * FROM table_name WHERE account_number = '$_GET[acct_num]' LIMIT 10";
$query = mysql_query($sql);
if (!$query)
echo mysql_error . "<p>";
while ($results = mysql_fetch_array($query)){
foreach ($results as $k => $v){
echo "$k = $v<br>";
}
}
}