Oracle - Loop through column names

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dimxasnewfrozen
Forum Commoner
Posts: 84
Joined: Fri Oct 30, 2009 1:21 pm

Oracle - Loop through column names

Post by dimxasnewfrozen »

I'm working with a database that has about 60 columns. I need to check to see that there are values in each column.

Is there a way to loop through the columns in php as apposed to looping through the rows?
Something like:

while (column['$i'] = 'x') {
echo 'column name';
$i++;
}

where i would be a column name and not a number.
dimxasnewfrozen
Forum Commoner
Posts: 84
Joined: Fri Oct 30, 2009 1:21 pm

Re: Oracle - Loop through column names

Post by dimxasnewfrozen »

Ah HA!

I figured it out:

Code: Select all

for ($j = 0; $j < $nrows; $j++ ) {
    foreach( $results as $key => $value){
        if ($value[$j] == 'X') {
        echo $key . "<br />";
           }
         }
}
So ultimately, I get the number of rows, then loop through the columns for each row which in this case is an associative array considering Oracles query functions store it that way.
Post Reply