Hi guys,

OK, here is what I have in mind. I have to be able to edit membership information, so I propose populating a form with the relevant information. But, I would like to populate the form depending on what member is chosen using a select box. Now, the form will be empty and only once the member has been selected via the select box will the form be populated. I don't want to have to navigate to another page. The select box will ideally be within the form itself. Also, will it be possible to cycle through the member information using the same form, ie. next record, previous record, etc.?

Dani AI

Generated

— there are two practical patterns to get an Access-style edit form without moving off the same page. and pointed toward adding a client-side layer; below is a server-first approach (works today with PHP/MySQL and gives a solid fallback) and a short checklist for hardening and later enhancement.

The basic idea: submit the form back to the same PHP script, let the server load the requested record and compute the next/previous record IDs, then render the same form populated with values. This keeps everything on one URL and requires no client-side coding to start.

<?php
// assume $pdo is a PDO connection
$member_id = isset($_POST['member_id']) ? (int)$_POST['member_id'] : 0;
$action = $_POST['action'] ?? '';

if ($action === 'next' && $member_id) {
  $stmt = $pdo->prepare('SELECT id FROM members WHERE id > :id ORDER BY id ASC LIMIT 1');
  $stmt->execute(['id'=>$member_id]);
  $member_id = (int)$stmt->fetchColumn() ?: $member_id;
} elseif ($action === 'prev' && $member_id) {
  $stmt = $pdo->prepare('SELECT id FROM members WHERE id < :id ORDER BY id DESC LIMIT 1');
  $stmt->execute(['id'=>$member_id]);
  $member_id = (int)$stmt->fetchColumn() ?: $member_id;
}

$member = [];
if ($member_id) {
  $stmt = $pdo->prepare('SELECT * FROM members WHERE id = :id');
  $stmt->execute(['id'=>$member_id]);
  $member = $stmt->fetch(PDO::FETCH_ASSOC) ?: [];
}

// build select options, then output the form with values using htmlspecialchars()
?>

Notes and practical tips

  • Use prepared statements and htmlspecialchars() for output. Treat edits as POST actions and validate server-side.
  • For Next/Prev use the LIMIT 1 queries shown above; they work even with gaps in numeric IDs.
  • Disable Next/Prev when no neighbour exists and show clear messages for empty results.
  • If the members table is large, populate the select with a search or limited result set to avoid huge HTML.
  • Keep this server flow as the working fallback; later you can add a small JSON endpoint and progressively enhance the same form with client-side calls once comfortable.

Recommended Answers

All 8 Replies

e same

Do you want someone to do the code for you? You could atleast attempt it. I don't get what question you're actually asking.

Don't want somebody to do the code for me at all. I will always attempt the code myself. Basically, I want a form to behave as if it were a form in Microsoft Access, ie. without refreshing you can cycle through records. Asking if this is at all possible using PHP.


You would need Java/JQuery to auto refresh the form on the change of the drop down.

Give your form an ID and call submit on it using something like:

$('#myform').submit();

where 'myform' is the id of your form

Or something like this

Hey, apologies.

You would need to use something like, jQuery/Ajax/Javascript in order to create this kind of functuanlity. You can use PHP to do the processing i.e. ("retriving / displaying data"). But the real-time, none-refreshing element would need to be done in a client-side language.

I guess it would be fairly easy to create it where you can show ("Next {#} Records") for example, as well as shifting through them.

No worries .
Thought it might have had to be something other than PHP. So, back to the headscratching for me as I have never had any dealings with JQuery/Ajax/Javascripting. Think it might just be a bit easier for me to write something locally in Access that will front-end my mySql database on the webserver and use that to edit the data in the tables. This is not functionallity that is totally necessary on the website anyway, just would have been a nice to have. Can always carry my laptop with me on trips out and connect using my mobile phone for wireless.

Hey , as above. I at this stage don't really feel up to JQuery, etc. Just getting my small brain around PHP is making an already grey head even greyer!

Guys, I think you both have just saved me a major headache!

op with me on trips out and connect using my mobile phone for wireless.

It's possible, I mean, don't give up! It's good to experiment with such things, and, once you start it'll all click into place. I mean, when do you need it by? Do you have a specification of how you want it to look like / function?

Don't need it by any given time frame. And any specs are of my own making. Thumb sucking comes to mind? Will definitely give it a go but at a later date. If I can get something working for now to help me edit the data easily then I think that will be the way. The fancy things can come a bit later. Still lots to do PHP wise, so will concentrate on that first. This is a site for a charity I helped setup, so can take my time on the fancy, nice to haves.

Providing the specification is clear and consise, and, depending on the purposes I would be more than happy to help you! P/m me to talk more?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.