I have done a search on one of my PHP pages, and displayed the results in a
table on another page.
Then when a button is clicked, i want to be able to display the table
information in editable form fields, so that the data may be altered and the
database updated.
Does anyone have any ideas how i may be able to carry this out? :-) It's the
parsing the data that i am unable to do.
Thanx Again
Yaz
____________________________________________________________ _____
Use MSN Messenger to send music and pics to your friends
http://www.msn.co.uk/messenger
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
Re: Parsing Data, Table to Form
am 09.05.2004 17:24:49 von gmr
Look at these functions in the php documentation:
pg_Query, pg_NumRows, pg_Fetch_Object, and pg_FreeResult
http://www.php.net/manual/en/ref.pgsql.php
Small example
$conn = pg_Connect("host=localhost dbname=test user=postgres");
$result = pg_Query($conn, "SELECT * FROM mytable ORDER BY id LIMIT 1
OFFSET 0;");
$rows = pg_NumRows($result);
if ( $rows == 0 )
echo "Sorry no data found.\n";
else {
$data = pg_Fetch_Object($result, 0);
pg_FreeResult($result);
echo "
\n";
}
Yasmine Kedoo wrote:
> Hi.
>
> I have done a search on one of my PHP pages, and displayed the results
> in a table on another page.
>
> Then when a button is clicked, i want to be able to display the table
> information in editable form fields, so that the data may be altered
> and the database updated.
>
> Does anyone have any ideas how i may be able to carry this out? :-)
> It's the parsing the data that i am unable to do.
>
> Thanx Again
>
> Yaz
>
> ____________________________________________________________ _____
> Use MSN Messenger to send music and pics to your friends
> http://www.msn.co.uk/messenger
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Re: Parsing Data, Table to Form
am 09.05.2004 17:38:35 von brew
Yaz......
> i want to be able to display the table information in editable form
> fields, so that the data may be altered and the database updated.
If by table information, you mean the information contained in the table,
then what I do is get one row's data and load it into variables. I use
the variables as the default text in the form (check the html standard).
After the user makes any edits he updates the entire row.
This only works with text boxes, with radio buttons and on/off buttons you
have to generate different html depending on the existing button state.
It's not complicated, just tedious to code if it has lots of buttons. If
it's only text it's easier. I think I started with an example someone
posted on php.net, maybe you can search for that and use it for reference,
too. I think it has a subroutine to generate the buttons preselected by
the existing state of the database.
My script is long, involving switches to display the possible rows to be
edited for a user on the first pass, then displaying the info for the row
selected in an editable form, then updating (or inserting the row if it
doesn't exist) and going back to displaying all the possible rows for that
user. I have to study it for a while myself, remembering how it works
before I make any changes to it! Hopefully somebody else has a more basic
example.
If by table information you mean the definition of a table in the
database, then that would be diferent, although still involving somewhat
the same type of script, just working on different database information.
All my table definitions are static in my database, so I've never done it
from a script, though.
brew
============================================================ ==============
Strange Brew (brew@theMode.com)
Check out my Musician's Online Database Exchange (The MODE Pages)
http://www.TheMode.com
============================================================ ==============
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings
Re: Parsing Data, Table to Form
am 10.05.2004 01:18:24 von Yasmine Kedoo
Hi again.
I have carried out a search, then displayed the results in a table on a php
page called admininfo.php:
but i am unable to write the information displayed in the table in
admininfo.php, to the textfields in updaad.php.
Has anybody got any suggestions? :-)
Thanx
Yaz
>From: brew@theMode.com
>To: Yasmine Kedoo
>Subject: Re: [PHP] Parsing Data, Table to Form
>Date: Sun, 9 May 2004 11:36:14 -0400 (EDT)
>
>
>Yaz......
>
> > i want to be able to display the table information in editable form
> > fields, so that the data may be altered and the database updated.
>
>If by table information, you mean the information contained in the table,
>then what I do is get one row's data and load it into variables. I use
>the variables as the default text in the form (check the html standard).
>After the user makes any edits he updates the entire row.
>
>This only works with text boxes, with radio buttons and on/off buttons you
>have to generate different html depending on the existing button state.
>
>It's not complicated, just tedious to code if it has lots of buttons. If
>it's only text it's easier. I think I started with an example someone
>posted on php.net, maybe you can search for that and use it for reference,
>too. I think it has a subroutine to generate the buttons preselected by
>the existing state of the database.
>
>My script is long, involving switches to display the possible rows to be
>edited for a user on the first pass, then displaying the info for the row
>selected in an editable form, then updating (or inserting the row if it
>doesn't exist) and going back to displaying all the possible rows for that
>user. I have to study it for a while myself, remembering how it works
>before I make any changes to it! Hopefully somebody else has a more basic
>example.
>
>If by table information you mean the definition of a table in the
>database, then that would be diferent, although still involving somewhat
>the same type of script, just working on different database information.
>All my table definitions are static in my database, so I've never done it
>from a script, though.
>
>brew
>
>
>=========================================================== ===============
> Strange Brew (brew@theMode.com)
> Check out my Musician's Online Database Exchange (The MODE Pages)
> http://www.TheMode.com
>
>=========================================================== ===============
>
____________________________________________________________ _____
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
Re: Parsing Data, Table to Form
am 10.05.2004 01:39:21 von Chris
Hi Yasmine,
If you click the link only, it will not submit the form and pass the
information on. You need to have a 'submit' button in your form and hit
that.
Chris.
-----Original Message-----
From: pgsql-php-owner@postgresql.org
[mailto:pgsql-php-owner@postgresql.org] On Behalf Of Yasmine Kedoo
Sent: Monday, May 10, 2004 9:18 AM
To: pgsql-php@postgresql.org
Subject: Re: [PHP] Parsing Data, Table to Form
Hi again.
I have carried out a search, then displayed the results in a table on a
php
page called admininfo.php:
but i am unable to write the information displayed in the table in
admininfo.php, to the textfields in updaad.php.
Has anybody got any suggestions? :-)
Thanx
Yaz
>From: brew@theMode.com
>To: Yasmine Kedoo
>Subject: Re: [PHP] Parsing Data, Table to Form
>Date: Sun, 9 May 2004 11:36:14 -0400 (EDT)
>
>
>Yaz......
>
> > i want to be able to display the table information in editable form
> > fields, so that the data may be altered and the database updated.
>
>If by table information, you mean the information contained in the
>table, then what I do is get one row's data and load it into variables.
>I use the variables as the default text in the form (check the html
>standard). After the user makes any edits he updates the entire row.
>
>This only works with text boxes, with radio buttons and on/off buttons
>you have to generate different html depending on the existing button
>state.
>
>It's not complicated, just tedious to code if it has lots of buttons.
>If it's only text it's easier. I think I started with an example
>someone posted on php.net, maybe you can search for that and use it for
>reference, too. I think it has a subroutine to generate the buttons
>preselected by the existing state of the database.
>
>My script is long, involving switches to display the possible rows to
>be edited for a user on the first pass, then displaying the info for
>the row selected in an editable form, then updating (or inserting the
>row if it doesn't exist) and going back to displaying all the possible
>rows for that user. I have to study it for a while myself, remembering
>how it works before I make any changes to it! Hopefully somebody else
>has a more basic example.
>
>If by table information you mean the definition of a table in the
>database, then that would be diferent, although still involving
>somewhat the same type of script, just working on different database
>information. All my table definitions are static in my database, so
>I've never done it from a script, though.
>
>brew
>
>
>=========================================================== ============
===
> Strange Brew (brew@theMode.com)
> Check out my Musician's Online Database Exchange (The MODE Pages)
> http://www.TheMode.com
>
>=========================================================== ============
>===
>
____________________________________________________________ _____
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faqs/FAQ.html
Re: Parsing Data, Table to Form
am 10.05.2004 14:22:56 von Paul Lynch
The task you are trying to do is easy enough once you understand the
steps involved.
From your example the following major steps (programs) are needed.
1. Display the data from the database in a table in HTML (admininfo.php)
2. Select one row from the table for update (I'm guessing this step is
intended).
3. Display selected row in a form in HTML for operator update. (updaat.php)
4. Write changes made in 3 back to postgresql database table.
(not_named_yet.php)
My way of doing this (and there are many other ways to do this) is to
have in step 2 the key or keys that will identify the row from the
database in the html as hidden fields.
echo "
value=\"$keyoftabledata\" >";
In the updaat.php program the hidden fields are assigned to php
variables using the $_POST ["yourkeyid"] like:
$keyforrow = $_POST["yourkeyid"];
You use the key to get the data again from the database and then display
it in the new form for update.
The final step involves the final php program picking up all the entered
data from the form and updating the database, again the key to the
database table may need to be hidden and assigned to variables.
If this is where you are trying to go I can expand or send you some
sample working php programs.
Hope this helps,
Paul
Yasmine Kedoo wrote:
> Hi again.
>
> I have carried out a search, then displayed the results in a table on
> a php page called admininfo.php:
>
> $row = pg_fetch_object($result, 0);
>
> $test = "";
>
> for ($rw = 0; $rw < $maxrows; $rw++)
> {
> echo "
";
>
> }
>
> Now, i would like to parse the information displayed in the table to
> textfields on the page updaad.php, i've used a link to do this:
>
>
>
> On the page updaad.php, i have displyed the textfields using the
> following code:
>
> echo "Admin ID Number:
> value=\"$fld\"> \n";
> echo "Name: \n";
> echo "Surname:
> value=\"$fld\"> \n";
> echo "Phone:
> />\n";
> echo "Email:
> />\n";
> echo "Username:
> value=\"$fld\"> \n";
> echo "Password:
> value=\"$fld\"> \n";
> echo "Building:
> value=\"$fld\"> \n";
> echo "Postcode:
> value=\"$fld\"> \n ";
> echo "\n";
>
> but i am unable to write the information displayed in the table in
> admininfo.php, to the textfields in updaad.php.
>
> Has anybody got any suggestions? :-)
>
> Thanx
>
> Yaz
>
>
>
>
>> From: brew@theMode.com
>> To: Yasmine Kedoo
>> Subject: Re: [PHP] Parsing Data, Table to Form
>> Date: Sun, 9 May 2004 11:36:14 -0400 (EDT)
>>
>>
>> Yaz......
>>
>> > i want to be able to display the table information in editable form
>> > fields, so that the data may be altered and the database updated.
>>
>> If by table information, you mean the information contained in the
>> table,
>> then what I do is get one row's data and load it into variables. I use
>> the variables as the default text in the form (check the html standard).
>> After the user makes any edits he updates the entire row.
>>
>> This only works with text boxes, with radio buttons and on/off
>> buttons you
>> have to generate different html depending on the existing button state.
>>
>> It's not complicated, just tedious to code if it has lots of
>> buttons. If
>> it's only text it's easier. I think I started with an example someone
>> posted on php.net, maybe you can search for that and use it for
>> reference,
>> too. I think it has a subroutine to generate the buttons preselected by
>> the existing state of the database.
>>
>> My script is long, involving switches to display the possible rows to be
>> edited for a user on the first pass, then displaying the info for the
>> row
>> selected in an editable form, then updating (or inserting the row if it
>> doesn't exist) and going back to displaying all the possible rows for
>> that
>> user. I have to study it for a while myself, remembering how it works
>> before I make any changes to it! Hopefully somebody else has a more
>> basic
>> example.
>>
>> If by table information you mean the definition of a table in the
>> database, then that would be diferent, although still involving somewhat
>> the same type of script, just working on different database information.
>> All my table definitions are static in my database, so I've never
>> done it
>> from a script, though.
>>
>> brew
>>
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
Re: Parsing Data, Table to Form
am 11.05.2004 06:35:02 von Paul Lynch
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:
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 "
";
}
// 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:
$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 "";
?>
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:
$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 "";
>
> 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
>
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
Re: Parsing Data, Table to Form
am 16.05.2004 14:14:15 von Paul Lynch
Hi Yasmine,
Could you post line 66 or point out which line is 66 in updaad.php.
From the error message I would expect it to contain something like:
pg_fetch_row($rowtoupdate, 0)
From your code, if this failed it would be before the display of data
in the form, and not after you click the update button. Which has me a
little perplexed. In fact I would expect clicking on the update button
to start loading program adupdate.php
as per instructions in this line:
echo "
Re: Parsing Data, Table to Form
am 17.05.2004 14:21:00 von Paul Lynch
Hi Yasmine,
A lack of error checking has caught us out here. Plus some syntax in the
select and where clause. The adid in admininfo table is an integer, and
I gave you code for using a character type key.
So change ... WHERE adid='$adid' to WHERE adid=$adid (drop the ' )
While there you could add some error condition checking like below:
$rowtoupdate = pg_exec($database, "SELECT adid, name, sur, phone, email,
username, password, building, postcode FROM admininfo
WHERE adid=$adid");
if ( ! pg_numrows($rowstoupdate) == 1 ) // expecting a single
row only
{
echo "
Error in getting information from table
";
// add whatever you want here to help you see what went wrong
} else{
list($formadid, $formname, $formsurname, $formphone, $formemail,
$formusername, $formpassword,
$formbuilding,$formpostcode) = pg_fetch_row($rowtoupdate, 0);
}
Keep going you're getting close.
Yasmine Kedoo wrote:
> Hey Paul.
>
> Yes, the error is exactly that :-). I've put in the following code on
> admininfo.php:
>
> else
> {
>
> $row = pg_fetch_object($result, 0);
>
> $test = "";
>
> for ($rw = 0; $rw < $maxrows; $rw++)
> {
>
> echo "
";*/
>
>
> pg_result($result,0,$adid);
> echo "";
> }
> }
>
> and on page updaad.php, the error:
>
> Warning: Unable to jump to row 0 on PostgreSQL result index 2 in
> /home/webpages/yamkedoo/Project/updaad.php on line 66
>
> is displayed, along with empty textfields. The relevant code for
> updaad.php is as follows:
>
> $adid = $_POST['adid'];
> $name = $_POST['name'];
> $surname = $_POST['surname'];
> $phone = $_POST['phone'];
> $email = $_POST['email'];
> $username = $_POST['username'];
> $password = $_POST['password'];
> $building = $_POST['building'];
> $postcode = $_POST['postcode'];
>
> $rowtoupdate = pg_exec($database, "SELECT adid, name, sur,
> phone, email, username, password, building, postcode FROM admininfo
> WHERE adid='$adid'");
>
> list($formadid, $formname, $formsurname, $formphone, $formemail,
> $formusername, $formpassword, $formbuilding,$formpostcode) =
> pg_fetch_row($rowtoupdate, 0);
>
> echo "";
>
> I am not too sure how to fix the error on page admininfo.php. Any
> ideas? It doesn't seem to be parsing the data to the textfields.
>
> Thanx again,
>
> Yasmine
>
>
>> From: Paul Lynch
>> To: Yasmine Kedoo , pgsql-php@postgresql.org
>> Subject: Re: [PHP] Parsing Data, Table to Form
>> Date: Sun, 16 May 2004 22:14:15 +1000
>>
>> Hi Yasmine,
>>
>> Could you post line 66 or point out which line is 66 in updaad.php.
>> From the error message I would expect it to contain something like:
>> pg_fetch_row($rowtoupdate, 0)
>>
>> From your code, if this failed it would be before the display of data
>> in the form, and not after you click the update button. Which has me
>> a little perplexed. In fact I would expect clicking on the update
>> button to start loading program adupdate.php
>> as per instructions in this line:
>> echo "
Re: Parsing Data, Table to Form
am 19.05.2004 06:59:24 von Paul Lynch
Hi Yasmine,
Just noticed a mistake in the error checking. I typed :
if ( ! pg_numrows($rowstoupdate) == 1 ) // expecting a single
row only
however $rowstoupdate should be $rowtoupdate - take out the 's' .
That will hopefully catch the lack of rows. Now the real problem lies
in the pg_exec statement. It is not getting the data from the table.
And its problem is possibly in the $database connection value. You
should have somewhere before the pg_exec a line like:
$database=pg_connect("dbname=your_db user=your_user");
The error that displays is not the cause of the error, it is back up in
the code that you need to look.
Hopefully you will find the missing or wrong piece up there.
It is also a good practice to include lots of error checks in your
program to help isolate where things are going wrong. It is also good
not to make typing errors when writing error checks :-[ as I did.
HTH
Paul
Yasmine Kedoo wrote:
> Hey Paul.
>
> I've actually used CHAR for the id, as it involves both numbers and
> letters. That's y i actually left the single inverted commas around
> $adid, '$adid'.
>
> So i too am confused as to why the code doesn't work. Can't put my
> finger on the problem at the mo, but still get the same error.
>
> Warning: Unable to jump to row 0 on PostgreSQL result index 2 in
> /home/webpages/yamkedoo/Project/updaad.php on line 66
>
> I've added ur suggestion, but still the same thing. If u could help
> any further, that would be great :-)
>
> Thanx again,
>
> Yasmine
>
>
>
>
>
>
>> From: Paul Lynch
>> To: pgsql-php@postgresql.org
>> Subject: Re: [PHP] Parsing Data, Table to Form
>> Date: Mon, 17 May 2004 22:21:00 +1000
>>
>> Hi Yasmine,
>>
>> A lack of error checking has caught us out here. Plus some syntax in
>> the select and where clause. The adid in admininfo table is an
>> integer, and I gave you code for using a character type key. So
>> change ... WHERE adid='$adid' to WHERE adid=$adid (drop the ' )
>> While there you could add some error condition checking like below:
>>
>> $rowtoupdate = pg_exec($database, "SELECT adid, name, sur, phone,
>> email, username, password, building, postcode FROM
>> admininfo WHERE adid=$adid");
>> if ( ! pg_numrows($rowstoupdate) == 1 ) // expecting a
>> single row only
>> {
>> echo "
Error in getting information from table
";
>> // add whatever you want here to help you see what went wrong
>> } else{
>> list($formadid, $formname, $formsurname, $formphone,
>> $formemail, $formusername,
>> $formpassword,
>> $formbuilding,$formpostcode) = pg_fetch_row($rowtoupdate, 0);
>> }
>>
>> Keep going you're getting close.
>>
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend