pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feeddisplaying a rowset in php...same column names
4+ messages / 4 participants
[nested] [flat]
* displaying a rowset in php...same column names
@ 2004-01-07 03:09 Michael Hanna <taojones@sympatico.ca>
2004-01-07 04:09 ` Re: displaying a rowset in php...same column names Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2004-01-07 11:14 ` Re: displaying a rowset in php...same column names Enver ALTIN <enver.altin@frontsite.com.tr>
0 siblings, 2 replies; 4+ messages in thread
From: Michael Hanna @ 2004-01-07 03:09 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: displaying a rowset in php...same column names
2004-01-07 03:09 displaying a rowset in php...same column names Michael Hanna <taojones@sympatico.ca>
@ 2004-01-07 04:09 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
1 sibling, 0 replies; 4+ messages in thread
From: Christopher Kings-Lynne @ 2004-01-07 04:09 UTC (permalink / raw)
To: Michael Hanna <taojones@sympatico.ca>; +Cc: pgsql-php
You need to switch your fetch mode to use column numbers, NOT column names.
Chris
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: displaying a rowset in php...same column names
2004-01-07 03:09 displaying a rowset in php...same column names Michael Hanna <taojones@sympatico.ca>
@ 2004-01-07 11:14 ` Enver ALTIN <enver.altin@frontsite.com.tr>
2004-01-07 19:36 ` Re: displaying a rowset in php...same column names Gavin M. Roy <gmr@ehpg.net>
1 sibling, 1 reply; 4+ messages in thread
From: Enver ALTIN @ 2004-01-07 11:14 UTC (permalink / raw)
To: Michael Hanna <taojones@sympatico.ca>; +Cc: pgsql-php
On Wed, 2004-01-07 at 05:09, Michael Hanna wrote:
> 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
SELECT foo as bar,bar as foo from footable
notice the "as" thingie. It would help.
--
__________
| |
| | Enver ALTIN (a.k.a. skyblue)
| | Software developer, IT consultant
| FRONT |
|==========| FrontSITE Bilgi Teknolojisi A.Þ.
|_____SITE_| http://www.frontsite.com.tr/
Attachments:
signature.asc (application/pgp-signature, 188B) download
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: displaying a rowset in php...same column names
2004-01-07 03:09 displaying a rowset in php...same column names Michael Hanna <taojones@sympatico.ca>
2004-01-07 11:14 ` Re: displaying a rowset in php...same column names Enver ALTIN <enver.altin@frontsite.com.tr>
@ 2004-01-07 19:36 ` Gavin M. Roy <gmr@ehpg.net>
0 siblings, 0 replies; 4+ messages in thread
From: Gavin M. Roy @ 2004-01-07 19:36 UTC (permalink / raw)
To: 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
>
>
Another way from assigning column names, if you dont want to do that...
instead of pg_Fetch_Object
$data = pg_Fetch_Array($result, $row);
/*
$data[0]: login
$data[1]: firstname
$data[2]: lastname
$data[3]: date_part
$data[4]: date_part
*/
*or*
$login = pg_Result($result, 0, 0);
$firstname = pg_Result($result, 1, 0);
$lastname = pg_Result($result, 2, 0);
$date1 = pg_Result($result, 3, 0);
$date2 = pg_Result($result, 4, 0);
Hope this helps
Gavin
Enver ALTIN wrote:
>On Wed, 2004-01-07 at 05:09, Michael Hanna wrote:
>
>
>>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
>>
>>
>
>SELECT foo as bar,bar as foo from footable
>
>notice the "as" thingie. It would help.
>
>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2004-01-07 19:36 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-01-07 03:09 displaying a rowset in php...same column names Michael Hanna <taojones@sympatico.ca>
2004-01-07 04:09 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2004-01-07 11:14 ` Enver ALTIN <enver.altin@frontsite.com.tr>
2004-01-07 19:36 ` Gavin M. Roy <gmr@ehpg.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox