From: David Mehler on
Hello,
What i'm trying to do certainly doesn't seem hard conceptually, but
coding it has been rough. I'm wondering if anyone has anything
similar.
I've got a database with records. The first time the page is accessed
the submit button won't be selected, so display information about the
record with a checkbox for selection. If a user selects a checkbox and
hits submit, display only that specific record in a form for editing,
once editing is complete feed the edited data back to the database.
I'd like all this to be done in a single sticky file.
If anyone has any code similar to this i'd appreciate getting a look,
mine is nonworking.
Thanks.
Dave.
From: Bastien Koert on
On Wed, Jul 14, 2010 at 9:59 AM, David Mehler <dave.mehler(a)gmail.com> wrote:
> Hello,
> What i'm trying to do certainly doesn't seem hard conceptually, but
> coding it has been rough. I'm wondering if anyone has anything
> similar.
> I've got a database with records. The first time the page is accessed
> the submit button won't be selected, so display information about the
> record with a checkbox for selection. If a user selects a checkbox and
> hits submit, display only that specific record in a form for editing,
> once editing is complete feed the edited data back to the database.
> I'd like all this to be done in a single sticky file.
> If anyone has any code similar to this i'd appreciate getting a look,
> mine is nonworking.
> Thanks.
> Dave.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Are you passing back the id of the record that you want to see as the
value for the checkbox? It should be a simple matter then of pulling
just that id

<?php

//check and set the id
$id = '';
if(!empty($_POST['id'])){
$id = (int)$_POST['id'];
}

$sql = "select * from table where 1 ";

if(!empty($id)){
$sql = " and record_id = $id ";
}

//run query here

....

?>
--

Bastien

Cat, the other other white meat
From: "Bob McConnell" on
From: David Mehler

> What i'm trying to do certainly doesn't seem hard conceptually, but
> coding it has been rough. I'm wondering if anyone has anything
> similar.
> I've got a database with records. The first time the page is accessed
> the submit button won't be selected, so display information about the
> record with a checkbox for selection. If a user selects a checkbox and
> hits submit, display only that specific record in a form for editing,
> once editing is complete feed the edited data back to the database.
> I'd like all this to be done in a single sticky file.
> If anyone has any code similar to this i'd appreciate getting a look,
> mine is nonworking.

Mine looks something like this

-----8<-------------------------------------------
$Submit = $_POST['Submit'];

if (isset($CCsubmit)) {
//////// DELETE
if ($Submit == "Delete") {
// Check to see if user authorized, then delete record

}
//////// NEW
else if ($Submit == "New" || $Submit == "Next"){
// Issue empty form or next record

}
//////// EDIT
else if ($Submit == "Save") {
// Validate and ssve the updated data. Reissue if validation
fails.

}
}
else {
// Issue form with initial data



}
-----8<-------------------------------------------

You should also check in the Save option to see if anything was actually
changed. The record shouldn't be updated if nothing was edited.

Bob McConnell
From: Ashley Sheridan on
On Wed, 2010-07-14 at 10:29 -0400, Bob McConnell wrote:

> From: David Mehler
>
> > What i'm trying to do certainly doesn't seem hard conceptually, but
> > coding it has been rough. I'm wondering if anyone has anything
> > similar.
> > I've got a database with records. The first time the page is accessed
> > the submit button won't be selected, so display information about the
> > record with a checkbox for selection. If a user selects a checkbox and
> > hits submit, display only that specific record in a form for editing,
> > once editing is complete feed the edited data back to the database.
> > I'd like all this to be done in a single sticky file.
> > If anyone has any code similar to this i'd appreciate getting a look,
> > mine is nonworking.
>
> Mine looks something like this
>
> -----8<-------------------------------------------
> $Submit = $_POST['Submit'];
>
> if (isset($CCsubmit)) {
> //////// DELETE
> if ($Submit == "Delete") {
> // Check to see if user authorized, then delete record
>
> }
> //////// NEW
> else if ($Submit == "New" || $Submit == "Next"){
> // Issue empty form or next record
>
> }
> //////// EDIT
> else if ($Submit == "Save") {
> // Validate and ssve the updated data. Reissue if validation
> fails.
>
> }
> }
> else {
> // Issue form with initial data
>
>
>
> }
> -----8<-------------------------------------------
>
> You should also check in the Save option to see if anything was actually
> changed. The record shouldn't be updated if nothing was edited.
>
> Bob McConnell
>


David, are you looking for something broad or specific? phpMyAdmin does
what you want, so might be a good starting point?

Thanks,
Ash
http://www.ashleysheridan.co.uk


From: "Tommy Pham" on
> -----Original Message-----
> From: Ashley Sheridan [mailto:ash(a)ashleysheridan.co.uk]
> Sent: Wednesday, July 14, 2010 11:29 AM
> To: Bob McConnell
> Cc: David Mehler; php-general
> Subject: RE: [PHP] updating a database
>
> On Wed, 2010-07-14 at 10:29 -0400, Bob McConnell wrote:
>
> > From: David Mehler
> >
> > > What i'm trying to do certainly doesn't seem hard conceptually, but
> > > coding it has been rough. I'm wondering if anyone has anything
> > > similar.
> > > I've got a database with records. The first time the page is
> > > accessed the submit button won't be selected, so display information
> > > about the record with a checkbox for selection. If a user selects a
> > > checkbox and hits submit, display only that specific record in a
> > > form for editing, once editing is complete feed the edited data back to
> the database.
> > > I'd like all this to be done in a single sticky file.
> > > If anyone has any code similar to this i'd appreciate getting a
> > > look, mine is nonworking.
> >
> > Mine looks something like this
> >
> > -----8<-------------------------------------------
> > $Submit = $_POST['Submit'];
> >
> > if (isset($CCsubmit)) {
> > //////// DELETE
> > if ($Submit == "Delete") {
> > // Check to see if user authorized, then delete record
> >
> > }
> > //////// NEW
> > else if ($Submit == "New" || $Submit == "Next"){
> > // Issue empty form or next record
> >
> > }
> > //////// EDIT
> > else if ($Submit == "Save") {
> > // Validate and ssve the updated data. Reissue if
> > validation fails.
> >
> > }
> > }
> > else {
> > // Issue form with initial data
> >
> >
> >
> > }
> > -----8<-------------------------------------------
> >
> > You should also check in the Save option to see if anything was
> > actually changed. The record shouldn't be updated if nothing was edited.
> >
> > Bob McConnell
> >
>
>
> David, are you looking for something broad or specific? phpMyAdmin does
> what you want, so might be a good starting point?
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>

I think David is looking for a solution to edit a row from a specific query in his own app where the authorized user will edit the selected row. There are several ways to accomplished this.

1) The fancy and less strain on the servers is via AJAX call. When the user click on the check box or some kind of button (link or form type), your javascript function will send that particular id back to server and load all the relevant info for editing in a div tag. Your div tag containing the form can then do update provided that it passes all the sanity and validation check. Upon the successful update, your code can then reload the table with the updated data.

2) The straight forward way is to use the same checkbox or button and submit the form (via onclick). That same page will detect the id and load all the relevant info and show the editing form via php's if or include. After the user submit the edit form and the data passes the sanity and validation check, your same PHP page can update the data and reload the updated data to display in the table. When you load the edit form, you can choose to display the original table data or not. If you do, it would create unnecessary strain on the servers, IMO.

3) Do #2 but implement caching to reduce the strain on the servers. This method will require you to maintain the cache for the updated data.

You'll have to look at your application design, the features & functionality of the site/application, your skillset (PHP, Javascript, XML, etc) and choose what you think is best.

Regards,
Tommy