The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> PostgreSQL Help
|
Displaying records
Discuss Displaying records in the PostgreSQL Help forum on Dev Shed. Displaying records PostgreSQL Help forum discussing administration, SQL syntax, or other PostgreSQL-related topics. PostgreSQL provides enterprise level database functionality at open source prices.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 29th, 2003, 10:36 AM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 30
Time spent in forums: 2 h 1 m 55 sec
Reputation Power: 10
|
|
Displaying records
I am beggining to using PostgreSQL and I have a question about how to display my database's records. This is the code I have:
PHP Code:
<html>
<head>
<title>Service Appointments Database</title>
</head>
<body>
<?php
include('../../adodb165/adodb.inc.php');
$conn = &ADONewConnection('postgres7');
$conn->PConnect('localhost','webadmin','password','dbname');
$result = $conn->Execute("SELECT * FROM serviceappts ORDER BY time DESC");
?>
<table border="1" cellpadding="3">
<tr>
<td bgcolor="#CCCCCC"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>ID</strong></font></td>
<td bgcolor="#CCCCCC"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Customer
Name</strong></font></td>
<td bgcolor="#CCCCCC"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Vehicle
Information</strong></font></td>
<td bgcolor="#CCCCCC"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Service
Advisor</strong></font></td>
<td bgcolor="#CCCCCC"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Date
Submited</strong></font></td>
<td bgcolor="#CCCCCC"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>View Record</strong></font></td>
</tr>
<?php
while($row = pg_fetch_row($result))
{
?>
<tr>
<td><?php echo $row["id"]; ?></td>
<td><font size=2 face=Verdana, Arial, Helvetica, sans-serif><?php echo $row["first_name"]; ?><?php echo " " ?><?php echo $row["last_name"]; ?></font></td>
<td><font size=2 face=Verdana, Arial, Helvetica, sans-serif><?php echo $row["year"]; ?><?php echo " " ?><?php echo $row["make"]; ?><?php echo " " ?><?php echo $row["model"]; ?>
</font> </td>
<td><font size=2 face=Verdana, Arial, Helvetica, sans-serif> <?php echo $row["advisor"]; ?></font></td>
<td>
<?
$datefromdb = $row['time'];
$year = substr($datefromdb,0,4);
$mon = substr($datefromdb,4,2);
$day = substr($datefromdb,6,2);
$hour = substr($datefromdb,8,2);
$min = substr($datefromdb,10,2);
$sec = substr($datefromdb,12,2);
$orgdate = date("l F d, Y h:i A",mktime($hour,$min,$sec,$mon,$day,$year));
?>
<? echo $orgdate; ?> </TD>
<td align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="view_service_appointment.php?id=<?php echo $row['id']; ?>">View</a></font></TD>
</tr>
<?php
}
?>
</table>
</BODY>
</HTML>
I am having a problem with the while($row = pg_fetch_row($result)). When I run this code I get the following message:
Warning: Supplied argument is not a valid PostgreSQL result resource in /home/hperez/public_html/mysite/pages/test/appointments.php on line 27
Can someone please help me with my code? Any help is appreciated. Thank you.
|

July 29th, 2003, 10:40 AM
|
 |
Introspective
|
|
Join Date: Nov 2001
Location: London, UK
|
|
|
This is most likey because your query is failing. Can you try just echoing the query onto the screen, then cut and paste it into a pg dialogue to see if it runs?
christo
__________________
This is me: http://chris.uk.com
|

July 29th, 2003, 10:44 AM
|
 |
Introspective
|
|
Join Date: Nov 2001
Location: London, UK
|
|
Incidentally, I'm surprised to see something like this, when you are using the ADODB abstraction layer:
Code:
while($row = pg_fetch_row($result))
{
surely that restricts you to fetching rows from pgsql result objects. is't there something you can use which is equivalemtn to PEAR::DB's $result->fetchRow() ?
just a thought
christo
|

July 29th, 2003, 10:44 AM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 30
Time spent in forums: 2 h 1 m 55 sec
Reputation Power: 10
|
|
|
I am able to echo the contents of my database onto the screen but I want to display them in a fancier way than just line by line.
|

July 29th, 2003, 10:48 AM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 30
Time spent in forums: 2 h 1 m 55 sec
Reputation Power: 10
|
|
THANK YOU!!!! It works. When I plugged in $result->fetchRow() it started to work. THANK YOU!!!!!
|

July 29th, 2003, 10:52 AM
|
 |
Introspective
|
|
Join Date: Nov 2001
Location: London, UK
|
|
np dude 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|