A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Flash PHP SQL chatroom

  1. #1
    the cheesy child bounceboy's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    323

    Flash PHP SQL chatroom

    Hello, I am trying to make a chatroom.

    what I have been doing is using php to send the message to a txt file. flash reads this txt file and puts it onto the chat.

    but i dunno why but the chat message keeps sending and sending...

    SOOOO

    It Turns out that its best to have a place you can store heaps of information without stuff getting too slow... I think SQL might be the job.

    SO THIS IS WHAT I NEED

    I need a tutorial or somebody to show me on how to make a flash, PHP, SQL chatroom that teaches you to connect with PHP and all that stuff.

    anyways hopefully i can get a chatroom working soon.

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    search GOOGLE - flash, PHP, SQL chatroom tutorial

  3. #3
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    This is probably the worst way to make a chat room. Just throwing that out there.

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    http://www.jackleaman.co.uk/test/wri..._autoLoad.html

    i have sent you this link before. saved to .txt file. show last 20 entries only.

    can you not make use of the methods in the zipped file ??

  5. #5
    the cheesy child bounceboy's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    323
    Ok just last night I made a chatroom with php and txt myself without the file a_modified.

    You see problem is, It has errors and stuff and I was hoping SQL was somewhere to store data into such as a chat message.

    but nevermind. I will just stick with the glitchy chatroom i made...

    and i guess SQL can't support a multiplayer online game either...?

  6. #6
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    bounceboy, you're using the most awkward technologies for what you want to do.

    Writing out to a text file with every message, and polling that text file every x seconds is extremely inefficient and accident prone.

    Even polling a database for that is messy.

    What you're digging into, you should look into a real time media server. Something like Red5 or FMS. Those are meant for these types of things. Chat rooms and multiplayer games.

  7. #7
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    may I oppose: real time servers do not run on your regular web space, so one needs to run them on the home computer or pay a hosting bill. For a general web site, with a chat just as one element, building the chat with traditional web technology certainly is an option.

    I have used a sql-based chat built on this schema:
    the database maintains an id column as well as a date column, and polls to the server (reasonable intervals seem to be in the 3-10 seconds range) send the last message id received. So if nothing happens, the poll response ist just the same id again - only new messages are actually sent over the network
    a new person in the chat can potentially request the last # messages or last # minutes before login

    Musicman

  8. #8
    the cheesy child bounceboy's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    323
    Musicman that sounds like what i am after. is there a tutorial or something?

  9. #9
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    unfortunately there is not.... so these are just code snippets
    database structure:
    Code:
    create table chat (
       id int not null auto_increment primary key,
       user varchar(20),
       posted int, -- actually a timestamp
       message text
    );
    Note: this assumes magic_quotes on, otherwise add addslashes()
    Code:
    <?
    include "db.php"
    if(isset($_POST['user']) && isset($_POST['message']))
    {     $user = $_POST['user'];
          $message = $_POST['message'];
           mysql_query("insert into chat (user, posted, message) values ('$user', unix_timestamp(), '$message')");
    }
    else if(isset($_POST['id']))
    {      $lastid = $_POST['id'];
           if(!ereg('^[1-9][0-9]*', $lastid)) exit;
            $ret = mysql_query("select * from chat where id > $lastid order by id");
            $chat = '';
            while($row = mysql_fetch_array($row))
            {       $chat .= "posted by <font color='#00ff00'>{$row['user']}</font> on " . date("h:m", $row['posted']) . "<br>" . htmlspecialchars($row['message']) . "<br>---------<br>";
                     $lastid = $row['id'];
            }
            if($chat != '') print "&chat=$chat";
            print "&id=$lastid&";
    }
    Now, on the flash side, an interval timer would repeatedly send the id to the server and get the id back. If there is a chat variable in the response, add to display (and possibly scroll to the end so it becomes visible)
    Code:
    var lastid = 0;
    function poll()
    {      var sendlv = new LoadVars();
           var retlv = new LoadVars();
           sendlv.id = lastid;
           retlv.onLoad = function() {
                lastid = this.id;
                if(this.chat != undefined) {
                     chattext.htmlText += this.chat;
                      chattext.scroll = chattext.maxscroll;
                }
           };
    }
    Musicman

  10. #10
    the cheesy child bounceboy's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    323
    Thank you very much! I will try this out as soon as I can.

    Also I've made a chatroom with PHP and TXT. the flash script is not very different...

  11. #11
    the cheesy child bounceboy's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    323
    wait wait.... are the first two codes for PHP?

    where does the first go?

    I'm not some expert at PHP sorry

  12. #12
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    the first one is definition of a database table, and the second one is a minimal php script that uses this database

    Musicman

  13. #13
    the cheesy child bounceboy's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    323
    dorry ummm im new to databases and this probably isn't the best way to start...

    i have made a database with my server, where do i go to create the table in the database... on my server i cant really edit it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center