Forum Moderators: open

Message Too Old, No Replies

Fetching the last record in a mysql table

         

me_great

8:53 pm on Mar 23, 2008 (gmt 0)

10+ Year Member



Hi,

I have some queries related to mysql.

1. Moving to first record / last record in a table on a php webform.

2.I want to update a mysql tablerow by checking the value of the primary key in the table with a text value on the form. The trouble is how do I refer to the "database field" from within the webform.

Thanks in advance.

rocknbil

10:44 pm on Mar 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't unless you pre-create an empty record, then you have a bunch of empty records when someone abandons the process. You should probably alter your logic to do any modifications after adding, example:

<input type="hidden" name="my_process" value="add_record">

........

sub add_record {
insert into table (values);
....
select id from table order by id desc limit 1;
# Then set the variable for "id" as this record
$var{'rec_id'} = $id;
# Now set the process to EDIT MODE and return to the form
$var{'process'} = 'update_record';
}

So when the form reloads, it is now in edit mode:

<input type="hidden" name="my_process" value="update_record">
<input type="hidden" name="rec_id" value="$var{'rec_id'}">