sql help needed!!

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

    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.

    #2
    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 

    Comment


      #3
      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

      Comment


        #4
        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

        Comment

        Working...
        X