tags:

views:

46

answers:

2

Hello, I have a while statement, echoing my whole database that match a WHERE parameter. How can I make it so when I click on something (anything for the moment), it updates that specific row. Here's my code.

                    while($request = mysql_fetch_array( $request_db )) {
                    echo "<tr><td style=\"width:33%;padding:1px;\">";
                    echo $request['SongName'];  
                    echo "</td><td style=\"width:33%;\">";
                    echo $request['Artist'];    
                    echo "</td><td style=\"width:33%;\">";
                    echo $request['DedicatedTo'];
                    echo "</td><td style=\"width:33%;\">";
                    echo "UPDATE A ROW's 'Hasplayed' value to '1'.";
                    echo "</td></tr>";  
                }
                echo "</table>";

Thanks!

EDIT: If you want an example, PHPmyAdmin can do this. Could I use some sort temporary cookie?

+1  A: 

Give the rows an id and do an ajax request via a link with the id of the db element as parameter. The server script reloads that db id and returns the fresh database values. :)

Juri Keller
Are there any other ways to achieve this? I am not very experienced in AJAX.
Sam
@Sam no, there is no way
Col. Shrapnel
+1  A: 

You can make a form and a button.
And update your table usual way, by handling this form with some PHP script.

You will need such a script anyway. Because no browser nor cookie can have access to your database. But only PHP script.

You can add to this script AJAX functionality later.

Col. Shrapnel
I was thinking about this, but does a form require some sort of <input>?
Sam
@Sam sure it does. though you can use javascript "onclick" property on any element, if you wish. what kind of control you want?
Col. Shrapnel
but you'd better to do it step by step. Add `input type = "submit"` first to test if it ever works
Col. Shrapnel
Is it possible to do this WITHOUT an input? Would it be as simple as adding a name attribute to a <p> or <div>, and whatever is in is is sent through?
Sam
@Sam yes, through javascript
Col. Shrapnel
Why must I use JavaScript to do this? I'm under the impression that all I have to do is wrap the text I want to send through in a <p>, <div> or <span> and then wrap that in a form like a normal form. Are there any tutorials or SO questions? A name for this process?
Sam
@Sam it is basic HTML question. The number of controls you can use is quite limited. To send a form to a server you can use either submit button or a javascript event emulating it. That's all.
Col. Shrapnel
I don't mind using a submit button, but the actual values of what the submit button would send, do these have to be <input> values?
Sam
@Sam yes. But what's the problem with it? Have no idea of hidden input types may be?
Col. Shrapnel
I do now :). Thanks for your help.
Sam
@Sam note that you can pass a variable not only using value, but also name of the input: `<input type="submit" name=id[273] value="Update">`. and you will have `$_POST['id'][273]="Update"` in your script. Or hidden fields.
Col. Shrapnel