467,222 Members | 1,421 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,222 developers. It's quick & easy.

Novice Postgres Query Question

I'm trying to query a postgresql database with PHP.

I am having a problem when using a WHERE. It works without the WHERE.

Example:

$query = "SELECT job_number, customer, desription, archive, date_opened,
job_status FROM jobs WHERE job_status='In Progress' ";
Returns this error in browser:
Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
in /usr/local/apache2/htdocs/jobs.html on line 23

Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
in /usr/local/apache2/htdocs/jobs.html on line 24

Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
in /usr/local/apache2/htdocs/jobs.html on line 24

Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
in /usr/local/apache2/htdocs/jobs.html on line 25

Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
in /usr/local/apache2/htdocs/jobs.html on line 26

Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
in /usr/local/apache2/htdocs/jobs.html on line 27

Warning: pg_result(): Unable to jump to row 28 on PostgreSQL result index 7
in /usr/local/apache2/htdocs/jobs.html on line 28
The full code I'm using is listed below: (with bad indents from newsreader)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Jobs Display</title>
</head>
<body>
<div id="content" class="feature" >
<table width="800" border="0">

<?php
include("jobs_masthead.html");

$db_handle = pg_connect("dbname=test user=postgres password=1234");

if( $db_handle ) {
$query = "SELECT job_number, customer, desription, archive,
date_opened, job_status FROM jobs WHERE job_status='In Progress' ";
$result = pg_exec($db_handle, $query);
if ( pg_numrows($result) != 0 ) {
for( $row = 0; $row < 40; $row++ ) {
print '<tr>';
print '<td class="bordercell" width="5%" ><input
type="checkbox" name="checkbox" value="checkbox"></td>';
print '<td class="bordercell" width="10%" >' . substr(
pg_result( $result, $row, 'job_number'), 0, 2) . "-" .
substr( pg_result( $result, $row, 'job_number'), 3, 4) . "-"
.. substr( pg_result( $result, $row, 'job_number'), 7, 2) . '</td>';
print '<td class="bordercell" width="25%" >' . pg_result(
$result, $row, 'customer' ) . '</td>';
print '<td class="bordercell" width="40%" >' . pg_result(
$result, $row, 'desription' ). '</td>';
print '<td class="bordercell" align="center" width="6" >' .
pg_result( $result, $row, 'archive' ) . '</td>';
print '<td class="bordercell" width="6" >' . pg_result(
$result, $row, 'date_opened' ) . '</td>';
print '<tr>';
}
} else {
print "There is no result.<br>";
}
} else {
print "No db_handle was made.<br>";
}
// print "Closing the db_handle.<br>";
pg_close($db_handle);

?>

</table>

</body>
</html>

May 4 '06 #1
  • viewed: 1105
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by OneSolution | last post: by
reply views Thread by Michal Kuna | last post: by
8 posts views Thread by wlcna | last post: by
6 posts views Thread by Prabu Subroto | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.