View Single Post
Old 03-02-2006, 10:25 AM   #1 (permalink)
tomycon
Registered User
 
Join Date: Jul 2002
Location: Massachusetts
Posts: 6
tomycon is on a distinguished road
Table data from db as new form input

Hi all,

Ive got a page with code that generates a table populated with values from a postgresql db. My code looks like this:
PHP Code:
    $dbconn pg_Connect ("dbname=bkadata user=httpd password=httpd");

    if (!
$dbconn) {
             echo 
"</table>An error occurred.\n";
             exit;
    }

    
$result pg_Exec($dbconn,
             
"SELECT joblog.job_no, joblog.job_name, joblog.status, joblog.bill_staff
                FROM joblog
                WHERE job_no >= 205000 AND job_no < 300000
                ORDER BY job_no DESC;"
);

    if (!
$result) {
             echo 
"</table>An error occurred.\n";
             exit;
    }

    
$num pg_NumRows($result);
    
$i 0;

    while (
$i $num) {
            if (
$i ==0) {
                
$bgcolor='#f3f3f3';
                } else {
                
$bgcolor='#e3e3e3';
                }
            echo 
"<TR bgcolor=$bgcolor><TD>";
            echo 
pg_Result($result$i"job_no");
            echo 
"</TD><TD>";
            echo 
pg_Result($result$i"job_name");
            echo 
"</TD><TD>";
            echo 
pg_Result($result$i"status");
            echo 
"</TD><TD>";
      echo 
pg_Result($result$i"bill_staff");
      echo 
"</TD></TR>";
            
$i++;
    }

    
pg_FreeResult($result);
    
pg_Close($dbconn); 
This works fine. Now I want to make the resulting table a form, with a submit icon in each row that will pass a value from the particular row chosen when a user clicks on the icon. The submit takes the user to another page where more info about the row chosen is displayed in another table generated from a new query to a different db.

So far I've got this code:
PHP Code:
$dbconn pg_Connect ("dbname=bkadata user=httpd password=httpd");

    if (!
$dbconn) {
             echo 
"</table>An error occurred.\n";
             exit;
    }

    
$result pg_Exec($dbconn,
             
"SELECT joblog.job_no, joblog.job_name, joblog.status, joblog.bill_staff
                FROM joblog
                WHERE job_no >= 205000 AND job_no < 300000
                ORDER BY job_no DESC;"
);

    if (!
$result) {
             echo 
"</table>An error occurred.\n";
             exit;
    }

    
$num pg_NumRows($result);
    
$i 0;

    while (
$i $num) {
            if (
$i ==0) {
                
$bgcolor='#f3f3f3';
                } else {
                
$bgcolor='#e3e3e3';
                }
                
$jobno[] = pg_Result($result$i"job_no");

            echo 
"<TR bgcolor=$bgcolor><TD>";
            echo 
"<INPUT TYPE=hidden  name=cntct_jno value=";
            echo 
$jobno[$i];
            echo 
">";
            echo 
$jobno[$i];
            echo 
"</imput></TD><TD>";
            echo 
"<input type=image src=contactb2.gif border=0 width=24 height=24 alt=contactb2.gif value=submit>";
            echo 
"</TD><TD>";
            echo 
pg_Result($result$i"job_name");
            echo 
"</TD><TD>";
            echo 
pg_Result($result$i"status");
            echo 
"</TD><TD>";
            echo 
pg_Result($result$i"bill_staff");
            echo 
"</TD></TR>";
            
$i++;
    }

    
pg_FreeResult($result);
    
pg_Close($dbconn); 
The above code displays the initial table with the new submit icon fine. But when I click on the icon for any row, it always passes the value for the last row in the table only!

I've tried several variations on the above code usually with the same result. What am I missing here?

Any help is appreciated!

Thanks!
tomycon is offline   Reply With Quote