traversing array, each troubles
Posted: Tue Aug 06, 2002 2:24 am
Hello! I'm having trouble going through the array that contains one row of the sql query that was applied. Each doubles all my results, except the first one ie. If I get from db columns name, address this code outputs name, address, address. (As many rows as query returned.) this is part of the listing function that is used in the system. The full sql query I used for testing is:
select rakennukset.nimi, tilat.nimi from tilat, rakennukset where rakennukset.rakennus_id = tilat.rakennus_id order by rakennukset.nimi, tilat.nimi asc
I tried to use
if ( !is_int ( $key ) ) before adding td, but then I'm not getting the first (name) listed attall
Any thoughts? code is below, if u want to take a look:
<update>
The column that gives me headache seems to be the only column that each is not doubling, how this can be? I know that each outputs 1 dimension 4 cell array that contains associative and numeric keys to the key and value. But are there any conditions that each returns associative or numeric keys only?
</update>
select rakennukset.nimi, tilat.nimi from tilat, rakennukset where rakennukset.rakennus_id = tilat.rakennus_id order by rakennukset.nimi, tilat.nimi asc
I tried to use
if ( !is_int ( $key ) ) before adding td, but then I'm not getting the first (name) listed attall
Any thoughts? code is below, if u want to take a look:
<update>
The column that gives me headache seems to be the only column that each is not doubling, how this can be? I know that each outputs 1 dimension 4 cell array that contains associative and numeric keys to the key and value. But are there any conditions that each returns associative or numeric keys only?
</update>
Code: Select all
require_once 'all_db_login.inc';
$list_result = pg_query($all_link, $sql);
$return = "<table class="listaus">";
/* Go through all rows, construct td by td....*/
$row = 0;
while ($data = @pg_fetch_object ($list_result, $row)) {
$return .= "<tr>";
while(list($key, $val) = each($data)){
$return .= "<td class ="listaus">".$val."</td>";
}
$return .="</tr>";
$row++;
}
$return .= "</table>";
return $return;
}