pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Paul Lynch <paul.lynch@exemail.com.au>
To: Yasmine Kedoo <yazkedoo@hotmail.com>
To: pgsql-php@postgresql.org
Subject: Re: Parsing Data, Table to Form
Date: Tue, 11 May 2004 14:35:02 +1000
Message-ID: <40A057F6.4040503@exemail.com.au> (raw)
In-Reply-To: <BAY14-F133RgQdcJNfQ0002198f@hotmail.com>
References: <BAY14-F133RgQdcJNfQ0002198f@hotmail.com>

Hi Yasmine,

Using your example as much as I can and assuming a single row is being 
selected for updating.  Your patid will be used in place of my 
keyoftabledata (key of table data) variable.

In admininfo.php:
<?php
for ($rw = 0; $rw < $maxrows; $rw++)
{
     for ($fld = 0; $fld < $maxfields ; $fld++)
    {
          echo pg_Result($result,$rw,$fld);
     }
    //  I will assume that the key field is the first field in your 
table result
    pg_result($result,0,$patid);               // add this line - you 
could combine in one line
    echo "<form method=post action=updaad.php>\n";
    echo "<input type=\"hidden\" name=\"patid\"value=\"$patid\" >"      
// add this line
    echo "<input type=\"submit\" value=\"Update\" >"                     
// add this line as well
    echo "</form>";
 }
// this will give an update button for each row of data from your result 
table
// I have left out the html table so as to simplify and avoid html 
issues between tables and forms
//  The only information being passed to updaat.php is the name patid 
and its value
?>

So updaat.php will have the following:

<?php
$patid =  $_POST["patid'];
// now use $patid to query the db for the row to update
$rowtoupdate = pg_exec($dbcon, "select patid, name, surname, phone, email
                            from your_table_name where patid=$patid" 
);      // patid is int ?
// where your_table_name is the name in postgresql
// and patid, name, surname, phone, email are the column names in the table
//
// add error checking etc here
// next lines assumes single row is available in $rowtoupdate
list($formatid,$formname,$formsurname,$formphone,$formemail) =
       pg_fetch_row($rowtoupdate, 0 );
// need to start new form
echo "<form method=post action=writeat.php>\n";       // name the next 
php program here
echo "Admin ID Number: <input type=text name=\"formadid\" 
value=\"$formatid\"><br />\n";
echo "Name: <input type=text name=\"formname\" value=\"$formname\"><br 
/>\n";
echo "Surname: <input type=text name=\"formsurname\" 
value=\"$formsurname\"><br />\n";
echo "Phone: <input type=text name=\"formphone\" 
value=\"$fornphone\"><br />\n";
echo "Email: <input type=text name=\"formemail\" 
value=\"$formemail\"><br />\n";
//  and so on for all your data
// need an update or accept button before writing back data changes
echo "<input type=\"submit\" value=\"Make Changes\" >"             
echo "</form>";
?>

So finally we have the program that puts the data back to the database.  
I have used writeat.php in this example, but use whatever name fits into 
your naming convention.

The essence of writeat.php:
<?php
$patid = $_POST["formatid"];
$name = $_POST["formname"];
$surname = $_POST["formsurname"]
$phone = $_POST["formphone"];
$email = $+POST["formemail"];
$dbcon = pg_connect("dbname=your_db_name user=your_user");
pg_exec( $dbcon, "update your_table_name
             set patid=$patid,               // allowing the key to be 
changed !!!!
                name='$name',
                surname='$surname',
                phone='$phone',
                email='$email'
                where patid=$patid" );
?>

This is only one way of doing the required steps and it leaves all error 
checking out .
One thing I don't like is allowing key fields to be changed so easily by 
operator input, but you may have valid reasons for this.  Generally I 
hide the key fields from update screens unless required or useful to see.
My real programs have a lot of additional stuff but I will try and find 
the simplest one to send to you off line.

Paul

 
Yasmine Kedoo wrote:

> Hi Paul.
>
> I think u do understand what i'm trying to do :-) , but i'm not too 
> sure i understand what u've told me ;-)
>
> Do i need to repeat the following line for each bit of data in the table:
>
> echo "<input type=\"hidden\" name=\"patid\"value=\"$keyoftabledata\" >";
>
> where 'patid' is the ID field in the database. But I am unsure what to 
> do with $keyoftabledata. What does this relate to?
>
> What does $keyforrow relate to here:
>
> $keyforrow = $_POST["yourkeyid"];
>
> Do i need to do this line a number of times for all data in the html 
> table?
>
> If u dont mind, it would be nice if u could send me some sample 
> programs relating to this topic.
>
> Thanx Again,
>
> Yasmine
>



view thread (10+ messages)  latest in thread

Message-ID: <40A057F6.4040503@exemail.com.au>
Permalink:  ../40A057F6.4040503@exemail.com.au/
Also on:    postgresql.org/message-id/40A057F6.4040503@exemail.com.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: paul.lynch@exemail.com.au, yazkedoo@hotmail.com
  Subject: Re: Parsing Data, Table to Form
  In-Reply-To: <40A057F6.4040503@exemail.com.au>
  References: <BAY14-F133RgQdcJNfQ0002198f@hotmail.com> <40A057F6.4040503@exemail.com.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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