php/mysql problem

Discussion in 'PHP' started by izlik, Sep 21, 2008.

  1. #1
    Hi

    I have a problem with a mysql code that wont work with my PHP code and i also need help with making a mysql query, please se 1: & 2: bellow. thanks to anyone that can help! :)

    Problem 1

    <?PHP
    mysql_query("UPDATE xtrm_users SET lastActive='".date("U"). WHERE $_SESSION["fid"]);
    ?>

    Parse error: syntax error, unexpected T_VARIABLE in /home/grabfrie/public_html/login.php on line 112

    Why is this not working ? :(

    Problem 2

    in my database i have a table called "xtrm_users" witch holds user information. now i was wondering how could i make a mysql query takes lines from "xtrm_users" at random and display it on my page with a limit of 10 at the time? each time you update the page the resaults given should be different.

    how can this be done ?
     
    izlik, Sep 21, 2008 IP
  2. mkoga

    mkoga Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Problem 1:
    it should be
    <?PHP
    mysql_query("UPDATE xtrm_users SET lastActive='".date("U"). "' WHERE somecolumns='".$_SESSION["fid"]."'");
    ?>
    
    PHP:
    Problem 2:
    mysql_query("select * from xtrm_users order by rand() limit 0,10");
    PHP:
     
    mkoga, Sep 21, 2008 IP
  3. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Problem 1 Solution

    You forgot to reopen your quotations after the date("U"):
    <?PHP
    mysql_query("UPDATE xtrm_users SET lastActive='".date("U")."' WHERE table_column_name='".$_SESSION["fid"]."'");
    ?>
    PHP:
    Also, you're missing the rest of the query.. At the end, you need something like WHERE table_column_name='{$_SESSION['fid']}'. You forgot to put what table column it should compare to that session variable.

    Problem 2 Answer

    mysql_query("SELECT * FROM xtrm_users ORDER BY RAND() LIMIT 10");
    PHP:
    EDIT: Posted same time as mkoga. :p
     
    zerxer, Sep 21, 2008 IP