0

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?

2
  • Comments seem to point towards ajax but you didn't indicate whether a page reload is allowed on click or not. Commented Jun 17, 2010 at 10:10
  • Apologies, I don't mind a page reload :). Commented Jun 17, 2010 at 10:16

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

9 Comments

I was thinking about this, but does a form require some sort of <input>?
@Sam sure it does. though you can use javascript "onclick" property on any element, if you wish. what kind of control you want?
but you'd better to do it step by step. Add input type = "submit" first to test if it ever works
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?
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?
|
1

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. :)

1 Comment

Are there any other ways to achieve this? I am not very experienced in AJAX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.