GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   mysql query, help needed, (https://gfy.com/showthread.php?t=1033217)

cooldude7 08-07-2011 06:42 AM

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.:helpme

blackmonsters 08-07-2011 06:43 AM

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


:2 cents:

cooldude7 08-07-2011 06:46 AM

Quote:

Originally Posted by blackmonsters (Post 18337447)
The best way to fix this is to stop using mysql.


:2 cents:

okie.,

thanks for your time. have a gr8 weekend.

woj 08-07-2011 06:49 AM

add "AND record_num<20000" to the WHERE clause? or am I misunderstanding what you want?

redwhiteandblue 08-07-2011 06:50 AM

$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.

cooldude7 08-07-2011 07:00 AM

Quote:

Originally Posted by redwhiteandblue (Post 18337450)
$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.

cooldude7 08-07-2011 07:02 AM

Quote:

Originally Posted by woj (Post 18337449)
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.

critical 08-07-2011 10:07 AM

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);

cooldude7 08-07-2011 10:28 AM

Quote:

Originally Posted by critical (Post 18337655)
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.:thumbsup

Nathan 08-07-2011 10:51 AM

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..

Tempest 08-07-2011 02:33 PM

Quote:

Originally Posted by cooldude7 (Post 18337444)
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.:helpme

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.


All times are GMT -7. The time now is 11:20 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc