Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5959985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:45:44+00:00 2026-05-22T18:45:44+00:00

I am making a chatbox IM. I have a table where I want to

  • 0

I am making a chatbox IM.
I have a table where I want to update if the user closes the window, meaning he has viewed the messages his friend has sent him.
When this happens, each conversation has a unique id so I find messages with that id and set the viewed column equal to the users name.

However if the other user also closes the window I would like to change the viewed column to ‘both’ for all the messages so none of those messages pops up for either user. (by default the viewed column is equal to 0).
What I want is a query that just finds all the messages with the convo_id and if that message is already viewed by another user meaning viewed!=0 then it is set to both else it is set to the user closing the box.

I have a query but it doesn’t work because I didn’t quite get the syntax right.

Just wondering if anyone could correct it or suggest something.

$sql = "UPDATE chatbox IF (viewed!=?) THEN
        SET viewed=? WHERE convo_id=?
        ELSE 
        SET viewed=? WHERE convo_id=?";
$stmt18 = $conn->prepare($sql);
$result = $stmt18->execute(array(0,$receiver,$convo_id,'both',$convo_id));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:45:44+00:00Added an answer on May 22, 2026 at 6:45 pm

    you’ll want to use a case statement:

    update catbox
    set viewed = case when viewed = ? THEN ? else ? end
    where convo_id = ?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a browser chat window in Javascript. I want to execute the
now, I'm making a chatbox. This is the code of the page were you
Making a word document of our network set-up. We have about 7 servers and
Making a simple application, so when the user logs out of Windows, it of
Making a mobile friendly site, I have a single field and a submit button.
Making an Flex App. Just wondering if anyone has created something that fits automatically
I'm making a Facebook-like chat. I want to implement the function that shows/hides the
I am making a chat application with PHP and AJAX and I want to
Making a small WCF test program which is based on a Store that has
making a multi-language site with codeginiter. I have created two folders. One for french

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.