Loading ...
Sorry, an error occurred while loading the content.
 

Re: [php4india] {Query} Random record from latest 10 entries...

Expand Messages
  • beski
    Try this: 1. To get latest 10 records, select * from tablename order by added_date desc limit 10 2. To display records in random: select * from tablename order
    Message 1 of 11 , Nov 22, 2007
      Try this:
      1. To get latest 10 records,
          select * from tablename order by added_date desc limit 10

      2. To display records in random:
          select * from tablename order by rand()

      3. to get latest 10 in random
          select * from tablename order by added_date desc,rand() limit 10
      wil not work, coz first step order by added date desc, second order by rand  ( here the desc order reset ) then only limit 10. Here we missed to get the latest 10 records.


      I found a way to use limit before rand().....
      Dont know how much effective.... but works.

      (SELECT * FROM `clients` order by client_id desc limit 10) union (SELECT * FROM `clients` where 0) order by rand()
      SELECT * FROM `clients` where 0 - 0 records query

      Expecting the correct way to solve this query from experts.

      Regards,
      Prathap Beschi.




      ----- Original Message ----
      From: Anees <anees_muhd@...>
      To: php 4 india <php4india@yahoogroups.com>; phpgroup1 <bang-phpug@yahoogroups.com>; phpgroup2 <php-objects@yahoogroups.com>
      Sent: Tuesday, 20 November, 2007 6:35:50 PM
      Subject: [php4india] {Query} Random record from latest 10 entries...

      HI

      I need to show a random image from Data base,
      and it should be from the latest 10 records

      How can i get it by executing only ONE query?
      Please help me

      Regards

      Anees Muhammed

      ___________



      Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.



      Now you can chat without downloading messenger. Click here to know how.
    • beski
      Try this: 1. To get latest 10 records, select * from tablename order by added_date desc limit 10 2. To display records in random: select * from tablename order
      Message 2 of 11 , Nov 22, 2007
        Try this:
        1. To get latest 10 records,
            select * from tablename order by added_date desc limit 10

        2. To display records in random:
            select * from tablename order by rand()

        3. to get latest 10 in random
            select * from tablename order by added_date desc,rand() limit 10
        wil not work, coz first step order by added date desc, second order by rand  ( here the desc order reset ) then only limit 10. Here we missed to get the latest 10 records.


        I found a way to use limit before rand().....
        Dont know how much effective.... but works.

        (SELECT * FROM tablename order by added_date desc limit 10) union (SELECT * FROM tablename where 0) order by rand()
        SELECT * FROM tablename where 0 -  records query

        Expecting the correct way to solve this query from experts.

        Regards,
        Prathap Beschi.


        ----- Original Message ----
        From: Anees <anees_muhd@...>
        To: php 4 india <php4india@yahoogroups.com>; phpgroup1 <bang-phpug@yahoogroups.com>; phpgroup2 <php-objects@yahoogroups.com>
        Sent: Tuesday, 20 November, 2007 6:35:50 PM
        Subject: [php4india] {Query} Random record from latest 10 entries...

        HI

        I need to show a random image from Data base,
        and it should be from the latest 10 records

        How can i get it by executing only ONE query?
        Please help me

        Regards

        Anees Muhammed

        ___________



        Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.



        Chat on a cool, new interface.. No download required. Click here.
      • Naga lingam
        Hi Anees, Is it working fine? From your concept, random id is generating from the numbers 0,9. So, it always return the image from 0 to 9th id only. Here, how
        Message 3 of 11 , Nov 25, 2007
          Hi Anees,
           
          Is it working fine?
           
          From your concept, random id is generating from the numbers 0,9.
          So, it always return the image from 0 to 9th id only.
          Here, how we will get the image from latest 10 entries?
          Are you giving the id 0 to 9 noly for the latest entries?
           
          Can you clarify above doubts?
           
           
          Thanks & Regards,
          Nagalingam.V
           
           
           
          Anees <anees_muhd@...> wrote:
          Hi,

          Thanks Guys for ur interest on my Query
          But,...

           if i use the query as Ramesh, varun krishnan and Pushparaj Thangaraj mentioned
          i will get 10 records in the result

          And in
          Sreeni .A's query i will get a RAND rec , But not from the latest 10 , from all the records!!
          that wasnt what am looking..... .

          Mean while i solved in this way with some guy's Idea

          $rand = rand(0,9);
          $qry = "SELECT image from table ORDER BY Id DESC LIMIT $rand,1;

          This gives a Random record from Latest 10 records
          Thanks... 

          Anees Muhammed

          ___________


          ----- Original Message ----
          From: Ramesh Selvaraj <ramesh.gates. sun@gmail. com>
          To: php4india@yahoogrou ps.com
          Sent: Wednesday, November 21, 2007 12:16:15 PM
          Subject: Re: [php4india] {Query} Random record from latest 10 entries...

          Hi,

          This query may useful to you.

          select * from <imagetable> ORDER BY <createddate> DESC LIMIT <yourrandomvalue>

          note *:

            <yourrandomvalue> -> generate random number 1 to 10 using random number generator and assign valuu to this place..



          On Nov 20, 2007 6:35 PM, Anees <anees_muhd@yahoo. com> wrote:
          HI

          I need to show a random image from Data base,
          and it should be from the latest 10 records

          How can i get it by executing only ONE query?
          Please help me

          Regards

          Anees Muhammed

          ___________



          Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.




          Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.


          Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now.

        • Naga lingam
          Hi Anees, I think this is the good solution for your problem. $rand = rand(0,9); $i = 0; $qry = mysql_query( SELECT image from table ORDER BY Id DESC LIMIT
          Message 4 of 11 , Nov 25, 2007
            Hi Anees,
             
            I think this is the good solution for your problem.
             
            $rand = rand(0,9);
            $i = 0;
            $qry = mysql_query("SELECT image from table ORDER BY Id DESC LIMIT 0,10");
            while($dat = mysql_fetch_array($qry))
            {
                if($i == $rand)
                {
                    $img_name = $dat['image'];
                }
                $i++;
            }
            echo $img_name; // random image
             
            Please let me know if you have any other easiest solution.
             
            Thanks & Regards,
            Nagalingam.V
             


            Anees <anees_muhd@...> wrote:
            Hi,

            Thanks Guys for ur interest on my Query
            But,...

             if i use the query as Ramesh, varun krishnan and Pushparaj Thangaraj mentioned
            i will get 10 records in the result

            And in
            Sreeni .A's query i will get a RAND rec , But not from the latest 10 , from all the records!!
            that wasnt what am looking..... .

            Mean while i solved in this way with some guy's Idea

            $rand = rand(0,9);
            $qry = "SELECT image from table ORDER BY Id DESC LIMIT $rand,1;

            This gives a Random record from Latest 10 records
            Thanks... 

            Anees Muhammed

            ___________


            ----- Original Message ----
            From: Ramesh Selvaraj <ramesh.gates. sun@gmail. com>
            To: php4india@yahoogrou ps.com
            Sent: Wednesday, November 21, 2007 12:16:15 PM
            Subject: Re: [php4india] {Query} Random record from latest 10 entries...

            Hi,

            This query may useful to you.

            select * from <imagetable> ORDER BY <createddate> DESC LIMIT <yourrandomvalue>

            note *:

              <yourrandomvalue> -> generate random number 1 to 10 using random number generator and assign valuu to this place..



            On Nov 20, 2007 6:35 PM, Anees <anees_muhd@yahoo. com> wrote:
            HI

            I need to show a random image from Data base,
            and it should be from the latest 10 records

            How can i get it by executing only ONE query?
            Please help me

            Regards

            Anees Muhammed

            ___________



            Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.




            Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.


            Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now.

          • beski
            Hi Anees, Hav u tried this one? (SELECT * FROM tablename order by id desc limit 10) union (SELECT * FROM tablename where 0) order by rand() pls reply about
            Message 5 of 11 , Nov 26, 2007
              Hi Anees,
              Hav u tried this one?

              (SELECT * FROM tablename order by id desc limit 10) union (SELECT * FROM tablename where 0) order by rand()


              pls reply about this..

              -Beschi.
              ----- Original Message ----
              From: Naga lingam <nagalv@...>
              To: php4india@yahoogroups.com; anees_muhd@...
              Sent: Monday, 26 November, 2007 1:28:42 PM
              Subject: Re: [php4india] {Query} Random record from latest 10 entries...

              Hi Anees,
               
              I think this is the good solution for your problem.
               
              $rand = rand(0,9);
              $i = 0;
              $qry = mysql_query( "SELECT image from table ORDER BY Id DESC LIMIT 0,10");
              while($dat = mysql_fetch_ array($qry) )
              {
                  if($i == $rand)
                  {
                      $img_name = $dat['image' ];
                  }
                  $i++;
              }
              echo $img_name; // random image
               
              Please let me know if you have any other easiest solution.
               
              Thanks & Regards,
              Nagalingam.V
               


              Anees <anees_muhd@yahoo. com> wrote:
              Hi,

              Thanks Guys for ur interest on my Query
              But,...

               if i use the query as Ramesh, varun krishnan and Pushparaj Thangaraj mentioned
              i will get 10 records in the result

              And in
              Sreeni .A's query i will get a RAND rec , But not from the latest 10 , from all the records!!
              that wasnt what am looking..... .

              Mean while i solved in this way with some guy's Idea

              $rand = rand(0,9);
              $qry = "SELECT image from table ORDER BY Id DESC LIMIT $rand,1;

              This gives a Random record from Latest 10 records
              Thanks... 

              Anees Muhammed

              ___________


              ----- Original Message ----
              From: Ramesh Selvaraj <ramesh.gates. sun@gmail. com>
              To: php4india@yahoogrou ps.com
              Sent: Wednesday, November 21, 2007 12:16:15 PM
              Subject: Re: [php4india] {Query} Random record from latest 10 entries...

              Hi,

              This query may useful to you.

              select * from <imagetable> ORDER BY <createddate> DESC LIMIT <yourrandomvalue>

              note *:

                <yourrandomvalue> -> generate random number 1 to 10 using random number generator and assign valuu to this place..



              On Nov 20, 2007 6:35 PM, Anees <anees_muhd@yahoo. com> wrote:
              HI

              I need to show a random image from Data base,
              and it should be from the latest 10 records

              How can i get it by executing only ONE query?
              Please help me

              Regards

              Anees Muhammed

              ___________



              Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.




              Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.


              Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now.




              Save all your chat conversations. Find them online.
            Your message has been successfully submitted and would be delivered to recipients shortly.