mysql query, help needed,

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cooldude7
    Confirmed User
    • Nov 2009
    • 4306

    #1

    mysql query, help needed,

    this is the original query and it throws whole data,

    $result = mysql_query("SELECT content.*, content_views.views AS views FROM content, content_views WHERE content_views.content = content.record_num AND content.approved = 2 AND content.enabled = 1 ORDER BY encoded_date");


    so i want to limit the values from column record_num from say 1 to 20k.
    record_num is kind of index so i can limit the output .

    how do i do this ?

    thanks for your time.
    Last edited by cooldude7; 08-07-2011, 05:43 AM.
  • blackmonsters
    Making PHP work
    • Nov 2002
    • 20967

    #2
    The best way to fix this is to stop using mysql.


    Free Open Source Live Aggregated Cams Script (FOSLACS)

    Comment

    • cooldude7
      Confirmed User
      • Nov 2009
      • 4306

      #3
      Originally posted by blackmonsters
      The best way to fix this is to stop using mysql.


      okie.,

      thanks for your time. have a gr8 weekend.

      Comment

      • woj
        <&(©¿©)&>
        • Jul 2002
        • 47882

        #4
        add "AND record_num<20000" to the WHERE clause? or am I misunderstanding what you want?
        Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
        Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
        Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

        Comment

        • redwhiteandblue
          Bollocks
          • Jun 2007
          • 2793

          #5
          $result = mysql_query("SELECT content.*, content_views.views AS views FROM content, content_views WHERE content_views.content = content.record_num AND content.approved = 2 AND content.enabled = 1 AND record_num<20000 ORDER BY encoded_date");

          BTW defining an alias for content_views.views as "views" is pretty pointless in this query.
          Interserver unmanaged AMD Ryzen servers from $73.00

          Comment

          • cooldude7
            Confirmed User
            • Nov 2009
            • 4306

            #6
            Originally posted by redwhiteandblue
            $result = mysql_query("SELECT content.*, content_views.views AS views FROM content, content_views WHERE content_views.content = content.record_num AND content.approved = 2 AND content.enabled = 1 AND record_num<20000 ORDER BY encoded_date");

            BTW defining an alias for content_views.views as "views" is pretty pointless in this query.
            damn this worked like charm, thanks a lot.
            so for fetching 20k to 40k should i do something like this .


            $result = mysql_query("SELECT content.*, content_views.views AS views FROM content, content_views WHERE content_views.content = content.record_num AND content.approved = 2 AND content.enabled = 1 AND record_num>20000 AND record_num<40000 ORDER BY encoded_date");


            thanks for your time.

            Comment

            • cooldude7
              Confirmed User
              • Nov 2009
              • 4306

              #7
              Originally posted by woj
              add "AND record_num<20000" to the WHERE clause? or am I misunderstanding what you want?
              thanks for your time, but i am complete noob in case of mysql,
              now i got the idea of using AND,

              thanks a lot.

              Comment

              • critical
                Confirmed User
                • Aug 2009
                • 478

                #8
                If you are trying to obtain a range, just use mysql's range function:

                May times the programmer needs to find out some specific data which lies in the particular range of values but there is not any predefined function in MySQL but we can also find that particular range's data from the database in MySQL using BETWEEN and AND clauses or write your own simple query.

                Syntax:

                exp BETWEEN min_value AND max_value
                The above syntax is equivalent to the expression (min_value <= exp AND exp <= max_value).

                In the following example we will describe you that how one can find out specific data lying between some range. To fire query we must have some data into a table therefore we will first create a table and fill some data into it.

                Example:

                SELECT id, name, subject from mca where
                mca.id BETWEEN 2 AND 5;
                Above query can also be written as below:

                SELECT id, name, subject from mca where
                ( mca.id >=2 && mca.id <=5);

                Comment

                • cooldude7
                  Confirmed User
                  • Nov 2009
                  • 4306

                  #9
                  Originally posted by critical
                  If you are trying to obtain a range, just use mysql's range function:

                  May times the programmer needs to find out some specific data which lies in the particular range of values but there is not any predefined function in MySQL but we can also find that particular range's data from the database in MySQL using BETWEEN and AND clauses or write your own simple query.

                  Syntax:

                  exp BETWEEN min_value AND max_value
                  The above syntax is equivalent to the expression (min_value <= exp AND exp <= max_value).

                  In the following example we will describe you that how one can find out specific data lying between some range. To fire query we must have some data into a table therefore we will first create a table and fill some data into it.

                  Example:

                  SELECT id, name, subject from mca where
                  mca.id BETWEEN 2 AND 5;
                  Above query can also be written as below:

                  SELECT id, name, subject from mca where
                  ( mca.id >=2 && mca.id <=5);
                  thanks for your time.,

                  because of ur explaination i have found something very useful for me.,


                  Code:
                  mysql> SELECT 1 BETWEEN 2 AND 3;

                  now my query looks like this., with start point and exnd point.,

                  $result = mysql_query("SELECT content.*, content_views.views AS views FROM content, content_views WHERE content_views.content = content.record_num AND content.approved = 2 AND content.enabled = 1 AND record_num BETWEEN 1000 AND 1200 ORDER BY encoded_date");



                  thanks a lot.

                  Comment

                  • Nathan
                    Confirmed User
                    • Jul 2003
                    • 3108

                    #10
                    you have a flaw in your logic though. What if encoding is not done in the row records are added? Then your record_num 2001 might be encoded before record_num 2000, and your order by logic becomes useless..
                    "Think about it a little more and you'll agree with me, because you're smart and I'm right."
                    - Charlie Munger

                    Comment

                    • Tempest
                      Too lazy to set a custom title
                      • May 2004
                      • 10217

                      #11
                      Originally posted by cooldude7
                      this is the original query and it throws whole data,

                      $result = mysql_query("SELECT content.*, content_views.views AS views FROM content, content_views WHERE content_views.content = content.record_num AND content.approved = 2 AND content.enabled = 1 ORDER BY encoded_date");


                      so i want to limit the values from column record_num from say 1 to 20k.
                      record_num is kind of index so i can limit the output .

                      how do i do this ?

                      thanks for your time.
                      LIMIT is used to grab "pages" of data..

                      SELECT content.*, content_views.views AS views FROM content, content_views WHERE content_views.content = content.record_num AND content.approved = 2 AND content.enabled = 1 ORDER BY encoded_date LIMIT 0,1000

                      LIMIT 0,1000 - get the first 1000 entries
                      LIMIT 1000,1000 - get the 2nd set of 1000 entries
                      LIMIT 2000,1000 - get the 3rd set of 1000 entries

                      If you don't use LIMIT, then really, you're ORDER BY has no meaning.

                      Comment

                      Working...