Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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>
   <?
	}

In response to

Responses

pgsql-php by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group