Home
| Calendar
| Mail Lists
| List Archives
| Desktop SIG
| Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU |
Hi All, I'm trying to generate a report in CSV format. I desire the column names in the first row. Oddly I'm outputing only the first few column names. Anybody in the mood to take a peak at my chicken scratch and point out a mistake? Many thanks. <code> // do query $v_all_members_0 =3D "select * from members_50congress where gym_name =3D '$v_gym_name';"; $v_all_members_1 =3D pg_query($dbconn, $v_all_members_0) or die('Query failed: ' . pg_last_error()); $rows =3D pg_num_rows($v_all_members_1); // count up rows in que= ry $rows =3D $rows -1; // avoids an index not found error // write file $report_file_name =3D 'output_am_'.date("YmdHi").'.csv'; $fp =3D fopen($report_file_name, 'w'); =09 // get column names and write to file // TODO: why the frack isn't this printing all column names? $i =3D 0; while ($i <=3D $rows) { fwrite($fp, pg_field_name($v_all_members_1,$i)); $i++; =09 if ($i <=3D $rows) { fwrite($fp, ','); } else { fwrite($fp, "\n"); } =09 } =09 // loop through rows and write to file $i =3D 0; while ($i <=3D $rows) { fputcsv($fp, pg_fetch_array($v_all_members_1,$i,PGSQL_NUM)); $i++; } fclose($fp); </code> Many thanks! Eric C
BLU is a member of BostonUserGroups | |
We also thank MIT for the use of their facilities. |