>Ok.. what I have is a database of first names and last names, and some other
>columns that don't matter here.
>
>A form is presented to a user, lets them enter a bunch of names, attributes
>of the person, etc.
>
>After submission, each record is checked against the current database to see
>if the name currently exists, or names similar to it exist.
>
>If so, it gives the option of either:
>
>a) entering the new record
>or
>b) selecting one of the existing records

Okay, here's one thing:
Why make me type all the crap in for somebody who might already be there?

It would be much better human interface to first let me know who's missing
before I go typing in all that stuff for the players already input.

I'm assuming LW and RW are, like, Left Wing and Right Wing in soccer or
hockey or something, right?

A team roster is going to be, what, 30 records at most?

Show me the current list and let me choose whom to edit, and give me a "New
Player" button.

>Example:
>
>Enter your names, positions:
>Joe Schmoe, LW
>Random Guy, RW
>
>(submit button)
>
>After DB check for existing users:
>
>Found:
>
>()  Joey Schmoe   Click radio button to se this record
>()  Create New Record
>
>
>No matches found for Random Guy, must be a new user.
>
>(submit button)
>
>
>My problem is keeping this data consistent form by form, and updating the
>data when an existing record is selected instead of creating a new one (the
>existing data needs to go into another table, so I need to grab the user id
># of the existing record, etc)
>
>Any thoughts on how to approach this?  After the first form, should I make a
>multi-dimensional array, and have the second form update/change the elements
>of it?  I haven't used any PHP arrays in this yet, just been messing with
>the HTML form array stuff..
>
>Sorry if this is confusing.. if any part needs clarification, please let me
>know.

If there are only a few fields, and not too many rows, one thing I
frequently do is display them with User IDs and then use 'NULL' as the ID
for a New Record, and have code something like this:

<?php
  require 'connect.inc'; # This just has one line "$connection =
mysql_connnect('localhost', 'user', 'pass');" in it.
  
  # Handle any FORM input:
  if (isset($lastname)){
    while (list($id, $ln) = each($lastname)){
      $fn = $firstname[$id];
      # Other fields the same way $xx = $xxxxxxxx[$id];
      if ($id == NULL || $id == 'NULL' && ($fn || $ln)){
        # New Player, but only if they've filled in a name:
        $query = "insert into players (firstname, $lastname, ...)
values('$fn', '$ln', ...)";
      }
      else{
        $query = "update players set firstname = '$fn', lastname = '$ln',
... where players_id = $id";
      }
      $update = mysql_query($query, $connection) or
error_log(mysql_error());
    }
  }
  
  # Display FORM
  $query = "select players_id, firstname, lastname from players order by
lastname, firstname";
  $players = mysql_query($query, $connection) or error_log(mysql_error());
  while (list($id, $fn, $ln) = mysql_fetch_row($players)){
    echo "  <TR>\n";
    echo "    <TD><INPUT NAME=lastname[$id] VALUE='", htmlentities($ln),
"'></TD>\n";
    echo "    <TD><INPUT NAME=firstname[$id] VALUE='", htmlentities($fn),
"'></TD>\n";
    # More fields here.  They can be Radio buttons or whatever, of course.
    echo "  </TR>\n";
  }
  # Output a row for a "New Player":
  echo "  <TR>\n";
  echo "    <TD><B>NEW:</B><INPUT NAME=lastname[NULL]></TD>\n";
  echo "    <TD><INPUT NAME=firstname[NULL]></TD>\n";
  # More fields here.  They can be Radio buttons or whatever, of course.
  echo "  </TR>\n";
  echo "</TABLE></FORM>\n";
?>

Now, this is not going to win any awards for Design or anything, but for a
busy admin to have everything in one place to fill in all the crap and see
all of it is very handy.

It also means that when (not if) they forget to update 'Joe Schmoe', they'll
see his record when they go to add in 'Betsy Buick' -- which means they just
might notice that it's out of date and fix it at the same time.

This simply gets unwieldy, though, if there are a ton of records, or "too
many" fields...

Still, I'm making the wild guess that for a team roster this is going to be
fine...

You can also output 5 or even 10 rows of the "New" row, if they frequently
have to put in a lot of players at once, but then you need to give them
*DIFFERENT* 'key' values inside the [], and change the "if ($id == NULL ||
$id == 'NULL' ...)" part to be more complex:

if (strstr($id, 'NULL') && ($fn[$id] || $ln[$id])){
.
.
.
  # Output five rows for a "New Player":
  for ($i = 1; $i <= 5; $i++){
    echo "  <TR>\n";
    echo "    <TD><B>NEW:</B><INPUT NAME=lastname[NULL$i]></TD>\n";
    echo "    <TD><INPUT NAME=firstname[NULL$i]></TD>\n";
    # More fields here.  They can be Radio buttons or whatever, of course.
    echo "  </TR>\n";
  }

-- 
Like Music?  http://l-i-e.com/artists.htm
Off-Topic:  What is the moral equivalent of 'cat' in Windows?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to