1
I am reading a table that has 12 fields (campo_1, campo_2, ..., campo_12).
After each reading of a record, I need to do a repeat treatment for each column (only changes the field name). So I need to repeat the code 12 times, one for each column.
I wonder if there’s any code that makes a loop, guy FOR
...NEXT
or something similar, where the treatment would be written only once, varying the name of the field.
Example of how I’m doing:
$string_sql = "select * from TABELA where CHAVE = '" . $key . "'";
$query = ibase_query($connection,$string_sql);
while ($row = ibase_fetch_object($query)) {
if ($row->CAMPO_1 <> 0) {
.......
.......
}
if ($row->CAMPO_2 <> 0) {
.......
.......
}
if ($row->CAMPO_3 <> 0) {
.......
.......
}
.......
.......
.......
.......
if ($row->CAMPO_12 <> 0) {
.......
.......
}
}
What I thought:
$string_sql = "select * from TABELA where CHAVE = '" . $key . "'";
$query = ibase_query($connection,$string_sql);
while ($row = ibase_fetch_object($query)) {
for ($x = 1 ; $x <= 12 ; $x++) {
if ($row->CAMPO_$x <> 0) {
.......
.......
}
}
}
Possible duplicate of Regastar Mysql column name and values
– rbz