SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Tampa
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to display results of a MYSQL query

    I have chat room and a forum and I'm trying to display w/ PHP current users in the chat room and current posts on the forum. I pretty ignorant but am willing to learn. I went into MYPHPADMIN and ran queries until I found the ones that worked for both now I want to find or write a PHP script that will display the results of the query. This is what I have so far and please don't laugh

    <?php

    $server = "localhost";
    $db_user = "xxxxx";
    $db_pass = "xxxxx";
    $database = "pdange11_pchat2";

    mysql_connect($server, $db_user, $db_pass);
    $sql = 'SELECT `c_users`.*, `c_users`.`u_time`'
    . ' FROM c_users'
    . ' ORDER BY `c_users`.`u_time` DESC LIMIT 0, 30'

    if(!($sql)) {
    print "Useronline Select Error > ";
    }

    $user = mysql_num_rows($sql);

    mysql_close();

    if($user == 1) {
    print("<b>$user</b> user online\n");
    } else {
    print("<b>$user</b> users online\n");
    }

    ?>

    This is supposed to query getting the latest people in the chat then limiting the results to 10. I get a parsing error. Anyone care to look this over and advise please do. Thanks and this board rocks!

  2. #2
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First, and maybe foremost:

    Take

    $server = "localhost";
    $db_user = "xxxxx";
    $db_pass = "xxxxx";
    $database = "pdange11_pchat2";

    out of the path to public_html.

    You are leaving yourself open to someone taking out your data.

    If you need help with this, just ask. But someone will try to hurt your sql and certainly for no reason, but they will.

  3. #3
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are missing 2 things (i think)

    FIRST
    $sql = mysql_query('SELECT `c_users`.*, `c_users`.`u_time`'
    . ' FROM c_users'
    . ' ORDER BY `c_users`.`u_time` DESC LIMIT 0, 30' );

    you forgot mysql_query();

    SECOND
    you din't select a database right after
    mysql_connect(). so try doing

    mysql_select_db('database') or die(mysql_error());


    and one thing when you did mysql_connect() try to do this just to make sure it is connected

    mysql_connect('host','uname','pass') or dfe(mysql_error());

    it might be the error. just give it a try


Bookmarks

Posting Permissions

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