I'm in a quandry.
I have a series of records in a table. I'm allowing NULLs on my varchar columns, because the imported data may not have values for some of them. I need to manipulate each record with the end-goal of creating another query which will be used to insert data into another table.
The first table, with the NULLS permitted, is the one I'm currently traversing with a 'while loop':
$sql = "select * from " . DB_TBL;
$result = mysql_query($sql);
while ($data = mysql_fetch_assoc($result)) {
//my foreach loop goes here
}
Pretty straightforward so far. So, I thought, was my foreach loop:
foreach ($data as $key => $value) {
if ((strlen($value) != 0)) {
echo "key: " . $key . ': =' . $value . '<br />';
} else {
echo '<br />';
}
}
When I run that, I seem to lose the first column, which is never NULL or strlen=0. It just doesn't display.
Should this be done another way? Perhaps getting the numrows first, then doing the foreach, incrementing the row inside a for/next loop?
thanks in advance for any productive ideas.