Jump to content

Updating a Single row from within a array result of 10 items


Hollows

Recommended Posts

I have an array that is pulling 10 results from a db like this -

 

<?php
$result = mysql_query("SELECT * FROM inbox ORDER BY id DESC LIMIT 0,10");
while ($row = mysql_fetch_array($result)) {

<div class="<?php echo $row['class'];  ?>">
<?php
echo $row['name'];
echo $row['message'];
?>
</div>

 

basically 'class' is defined in an earlyier part of the script and is used to tell the css what class to display - as I'm sure you can see.

 

What I'd like todo then be able to update the class of a message once I have read it, so update the class table with something like 'read' so the css will then be based on .read not what ever was set by the form, either using a link or form button inside each of the 10 results from the array.

 

I've managed to update one by using -

mysql_query("UPDATE shoutbox SET class = 'read' WHERE id = ''XX"); // XX should be row id

 

But I had to set that myself and point the id to the row id I wanted to change - How can I have that already populated with the row for the id that triggered it?

 

 

To be clear so it looks like -

 

Name

Message

read button

_____________

Name

Message

read button

_____________

Name

Message

read button

_____________

 

and so on...

 

 

Would I be better going by check boxes and one submit button? If so how could I implement that?

 

 

I can provide the full code I've written if it helps

 

Thank you in advance

Link to comment
Share on other sites

Hi

 

When do you want to mark them as read? When they appear on that screen or when the "read" button is pressed.

 

I assume when the "read" button is pressed you want to retrieve the message and display it, and mark it as read at that moment. As such you probably want "read" to be a link to another page, passing the ID across. Then you read the table and display the message based on the passed ID, and then update the table to mark that message as read based on the passed ID.

 

All the best

 

Keith

Link to comment
Share on other sites

Hi

 

Thank you for the reply, If I'm honest you've lost me abit, if I could explain the overall concept I'm working on, I have a form that listeners to our internet station can fill in with a name, a message and then a drop down box to choose if this is a request for a song or a message to be read out on air, the script I've written then populates the db with all the info, then a page inside radio control panel fetches the results and displays them. The original drop down box choice is then used to choose a css class for that specific result, so more important messages appear with a red border or something.

 

This all works perfect but would I'd like to do is once the current radio host had read a message or played a song, they click a link generated within the message that updates the row originally populated by the drop down box with something such as "read" or "expired".

 

That way I can also have a css class for this, so when the ajax refresh is triggered, old messages then change colour and new ones stand out again..

 

 

Does this sound like something that is relativley straight forward to achieve?

 

 

Again, thank you for your reply

Link to comment
Share on other sites

Hi

 

It does.

 

All you need to do is make the read button trigger a script.

 

Either have it trigger a refresh of the page but passing back the id of the message you want to mark as read. Your script to display the page would then check for being passed that id and if passed would do the update of the table (based on the ID) before doing the rest of the processing as it currently does.

 

Alternative would be to have the button trigger an Ajax script to do this and allow the page to refresh normally using Ajax (presume you use some kind of timer to trigger a refresh with Ajax), or just force the Ajax refresh.

 

However beyond this basic level I am not sure I can help more without knowing the details of the scripts you are currently running.

 

All the best

 

Keith

Link to comment
Share on other sites

Hi

 

It does.

 

All you need to do is make the read button trigger a script.

 

Either have it trigger a refresh of the page but passing back the id of the message you want to mark as read. Your script to display the page would then check for being passed that id and if passed would do the update of the table (based on the ID) before doing the rest of the processing as it currently does.

 

Alternative would be to have the button trigger an Ajax script to do this and allow the page to refresh normally using Ajax (presume you use some kind of timer to trigger a refresh with Ajax), or just force the Ajax refresh.

 

However beyond this basic level I am not sure I can help more without knowing the details of the scripts you are currently running.

 

All the best

 

Keith

 

You've actually solved it for me right there thank you  :D

 

I've essentially set my ajax script to be triggered by calling

<a href="update.php?id=<?php echo $row['id']; ?>">read</a>

 

and then using $id = $_GET['id']; in my update script + UPDATE shoutbox SET class = 'read' WHERE id = '$id' in the query, works an absolute treat thank you  8)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.