Thanks. Updating into the database is working now!  But when I select
one result from the list of results using the arrow keys the incorrect
selection is updated in the database.

If I don't use the arrow keys and just select the first result then
the correct result is in the database.  How do I make sure the result
the user selects is put into the database?  It seems to give me the
first result in the list by default.

Thanks!

On Nov 19, 1:48 pm, "Ron Newman" <[EMAIL PROTECTED]> wrote:
> If you're asking about the PHP part, all you need is an ID field in your
> database table:
>
> table fields:
> ID
> UNIQUE_CUST_ID
>
> Judging by your code, UNIQUE_CUST_ID is probably text, something you can
> enter in a user form.  I'd change it to something meaningful, like
> 'ARTISTNAME'.  And ID would be just a number assigned by the database.  It
> should be defined 'auto_increment' so that it is automatically assigned
> whenever you add a new entry, and is guaranteed to always be unique.
>
> So, you change:
>  $sql = "SELECT ARTISTNAME FROM tablename WHERE ARTISTNAME LIKE '%" .
> $_POST['search'] . "%'";
>
> To:  "SELECT ID, ARTISTNAME..."
>
> Then using your code below, you get
> $data["ID"]  has the ID number in it,
> $data["ARTISTNAME"] has the name.
>
> Then the crux of the matter:
> You do an UPDATE:
> $sql = UPDATE tablename set ARTISTNAME='your new value' WHERE ID=$data["ID"]
>
> This is two database queries.  You can do it in one, but I'd get this going
> first.  To do it in one, you use 'ON DUPLICATE ENTRY..." and some more
> stuff.
>
> Ron
>
> On Wed, Nov 19, 2008 at 3:22 PM, alohaaaron <[EMAIL PROTECTED]> wrote:
>
> > Hi, I'm trying to update my database with the string that is selected
> > by the user but am not sure how to do so?  Thank you.
>
> > Here is my call in html.
>
> > <td name='search' id='search' value='' ></td>
> > <div id='autocomplete_choices' class='autocomplete'></div>
>
> >  <input type="hidden" id="artist_id" name="artist_id" value=""/>
> >                                 <script type='text/javascript'
> > language='javascript'
> > charset='utf-8'>
> >                                 // <![CDATA[
> >                                          new
> > Ajax.Autocompleter('search','autocomplete_choices','ajax-
> > autocompletion/server.php',{minChars: 3,afterUpdateElement :
> > getSelectedId});
> >                                // ]]>
>
> >                                function getSelectedId(text, li) {
> >                                        $('artist_id').value=li.id;
> >                                }
> >                                </script>
>
> > The PHP code from wiseguys
>
> >        $sql = "SELECT UNIQUE_CUST_ID FROM MyDB WHERE UNIQUE_CUST_ID
> > LIKE
> > '%" . $_POST['search'] . "%'";
> >        $rs = mysql_query($sql);
> > ?>
>
> > <ul>
>
> > <? while($data = mysql_fetch_assoc($rs)) { ?>
> >  <li><? echo stripslashes($data['UNIQUE_CUST_ID']);?></li>
> > <? } ?>
> > </ul>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to