1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Chat Box in PHP

Discussion in 'PHP' started by cat_fich, Dec 19, 2009.

  1. #1
    I was thinking in doing a Chat Box in PHP. For that I would use a form with two fields, Nick and Message, then I would store the data in a DB and show them.
    I have already made the code for this. In the Chat Boxes I saw there the tima/date always appears in front of the messages.
    I don't need the time but I'd want to send to a database field the date of the moment when the user clicks the subtim button for orientation purposes.
    Can someone give me an hint on how to do this?
    Thanks
     
    cat_fich, Dec 19, 2009 IP
  2. Brandon_R

    Brandon_R Peon

    Messages:
    330
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You would need to use Javascript, specifically AJAX for the submitting and retrieving of the messages without page reloading. May i suggest Yahoo's YUI. It has many nice functions. Also jQuery can do the same. Logically here is how an AJAX Chatbox works

    User Enters Text In A Form And Press Enter
    Sends the Text To A PHP File VIA AJAX And Inserts It etc
    After Insertion, Echos That Message Plus The Last X ex (20)
    Then The AJAX Response Handler Captures The Echo Of The PHP Script And Sets The Message Box To It. ie div.innerHTML = ajax.responceText

    You might also have to implement an auto refresh for every X seconds.
     
    Brandon_R, Dec 19, 2009 IP
  3. KEEP IT REAL

    KEEP IT REAL Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You dont need time but you need date? lol
    What do you mean by that? the exact time Hours:Minutes:Seconds ?
     
    KEEP IT REAL, Dec 19, 2009 IP
  4. cat_fich

    cat_fich Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I want to show the date on which the user clicked the submit button. The time isn't mandatory, the user can guide himself by the date not to post in a chat box that hasn't been used for a year lol. But if the time doesn't require extra work of course I want to show it too.
    I only want to do this if it doesn't involve AJAX or other programming languages I don't know.
    In this site for example: http://speakabout.6te.net/
    The user submits a new topic and it appears in the frontpage with the date on which it was submitted.

    I don't need an auto-refresh function or something like that, it's a simple school project, I have less that two weeks to finish it lol.
    I've two form fields and a submit button. I want to store the date on whick the user has clicked the button.
    Is AJAX needed to do this?
    This won't work? http://dev.mysql.com/doc/refman/5.0/en/timestamp.html
    Thanks for your help
     
    Last edited: Dec 19, 2009
    cat_fich, Dec 19, 2009 IP
  5. KEEP IT REAL

    KEEP IT REAL Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    oh its easy, you need just this
    //month-date-year
    $date = date("m-d-Y");
    PHP:
    if you also need time then
    $date_time = date("m-d-Y H:i:s");
    PHP:
    And then just add date var to ur database
     
    KEEP IT REAL, Dec 19, 2009 IP
  6. tygas

    tygas Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    just google for ajax chat and you will get a lot of them
     
    tygas, Dec 20, 2009 IP
  7. jobykjoseph10

    jobykjoseph10 Well-Known Member

    Messages:
    194
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    #7
    Just go through opensourcetips.org/chat . If you like it please PM me. I will give the code.
     
    jobykjoseph10, Dec 29, 2009 IP