displaying a rowset in php...same column names

From: Michael Hanna <taojones(at)sympatico(dot)ca>
To: pgsql-php(at)postgresql(dot)org
Subject: displaying a rowset in php...same column names
Date: 2004-01-07 03:09:34
Message-ID: EB366B10-40BE-11D8-8D6A-000A95B34330@sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

This query: SELECT login, firstname, lastname, date_part('epoch',
lastlogin), date_part('epoch', regdate) FROM admin ORDER BY login

results in:

login | firstname | lastname | date_part |
date_part
-----------+------------------+-----------------+------------------
+------------------
| Joe | Blo | 1073244631.3063 |
1073244631.3063
M.too | Me | too | 1073245739.87669 |
1073245739.87669
admin | admin first name | admin last name | 1073166434.11792 |
1073166434.11792
m.four | Me | four | 1073246991.60247 |
1073246991.60247
m.three | Me | three | 1073246781.73784 |
1073246781.73784
superuser | admin first name | admin last name | 1073166417.11391 |
1073166417.11391
(6 rows)

with two columns of the same name. how do I reference those columns
individually in PHP 4.32?

One try:

$query = "SELECT login, firstname, lastname, date_part('epoch',
lastlogin), date_part('epoch', regdate) FROM admin ORDER BY login";
$result = pg_query($connection, $query) or die("Error in query:
$query. " . pg_last_error($connection));

$rows = pg_num_rows($result);

echo $rows;

//for($i=0; $i<$rows; $i++) {

//}


for ($i=0; $i<$rows; $i++)
{
$row = pg_fetch_array($result, $i, PGSQL_ASSOC);
?>
<tr>
<td width="24%"><? echo $row['login']; ?></td>
<td width="27%"><? echo $row['firstname']; ?></td>
<td width="23%"><? echo $row['lastname']; ?></td>

<?
//echo $row['lastlogin'];
$lastlogintime = $row['lastlogin'];
echo $lastlogintime."<BR><BR>";
$lastlogintime = strtotime($lastlogintime);
echo $lastlogintime."<BR><BR>";

?>
<td width="22%"> <!-- want to insert the lastlogin here --></td>
<td width="4%"><!-- want to insert the regdate here --> </td>
</tr>
<?
}

how do I get this to work? do I need to convert the $row to a 2d php
array? How do I do that?

Michael

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Christopher Kings-Lynne 2004-01-07 04:09:20 Re: displaying a rowset in php...same column names
Previous Message Steve Crawford 2003-12-29 22:02:35 Re: SQL convert UTC to MST