sql help needed!!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • antony2kx
    replied
    PHP Code:

    $x
    =mysql_query("SELECT message, username, groupid, mstime FROM b_shout ORDER BY mstime DESC LIMIT 0,15");
    $messages = array();

    while(
    $m=mysql_fetch_object($x))
    {

       
    $messages[] = $m;
    }

    $random_val mt_rand(0count($messages)-1);
    $random_message $messages[$random_val];

    echo 
    $random_message->message//will display a message from the 15 you have selected 
    This is because you used the $db->query, your using a class and i dont know if it returns resource or what so i changed it to mysql_query instead

    Leave a comment:


  • icedroplet1987
    replied
    Originally posted by antony2kx View Post
    using your sql statement

    do this
    PHP Code:

    $x
    =$db->select("SELECT message, username, groupid, mstime FROM b_shout ORDER BY mstime DESC LIMIT 0,15");
    $messages = array();

    while(
    $m=mysql_fetch_object($x))
    {

       
    $messages[] = $m;
    }

    $random_val mt_rand(0count($messages)-1);
    $random_message $messages[$random_val];

    echo 
    $random_message->message//will display a message from the 15 you have selected 
    getting this error mate..

    Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource
    Notice: Undefined offset: 0
    Notice: Trying to get property of non-object

    Leave a comment:


  • antony2kx
    replied
    using your sql statement

    do this
    PHP Code:

    $x
    =$db->select("SELECT message, username, groupid, mstime FROM b_shout ORDER BY mstime DESC LIMIT 0,15");
    $messages = array();

    while(
    $m=mysql_fetch_object($x))
    {

       
    $messages[] = $m;
    }

    $random_val mt_rand(0count($messages)-1);
    $random_message $messages[$random_val];

    echo 
    $random_message->message//will display a message from the 15 you have selected 

    Leave a comment:


  • icedroplet1987
    started a topic sql help needed!!

    sql help needed!!

    $x=$db->select("SELECT message, username, groupid, mstime FROM b_shout ORDER BY mstime DESC LIMIT 0,15");

    friends, as i know this line is to select data from database and as limit defined to 15 so it seects 15 rows.
    but i want to select single row inbetween condition without changing anything in this line. likewise i will like to select only one message, how should i do it? hope you got my point.
Working...
X