tags:

views:

442

answers:

4

I was trying to execute this mysql query it is not giving me any results if i set the query_limit to more than 100, can somebody point me what i can do to get this working for fetching more data.

$query_limit = 190;
$query1 = "SELECT N.nid ,N.tid FROM term_node N JOIN term_data S  ON  S.tid = N.tid AND S.vid =1";
$query_result = db_query_range($query1, $vid, 0, $query_limit);
A: 

no results out of a query means you have no rows in your tables that match your join condition.

longneck
i do have data that matches the query
pmarreddy
+1  A: 

If you are using Drupal7 you may be incorrectly calling the db_query_range function. http://api.drupal.org/api/function/db_query_range/7:

db_query_range($query, $from, $count, array $args = array(), array $options = array())

$count The number of records to return from the result set.
Chris
i tried WHERE still not working if i take WHERE s.vid =1 its working
pmarreddy
what? Are you saying if you remove `WHERE s.vid = 1` it works? Then you don't have any data in term_data that has `vid = 1`.
Chris
the queries are working in phpmyadmin but not working in drupal, no idea why
pmarreddy
double check and make sure that you are using the same database instance.
Chris
using the same databases
pmarreddy
i figured out the problem is with the no of rows or the query limit in drupal which is working for less than 100, can somebody tell me how to solve this problem in drupal
pmarreddy
You are telling drupal to return 0 rows with your third parameter.
Chris
i think it is some kind of memory problem because if i remove some parts of teh query i could increase to 300, "SELECT N.nid ,N.tid FROM term_node N
pmarreddy
300 hundred records wouldn't be causing a memory problem. If you get 300 record by removing the JOIN statement and keeping all the rest of the code the same, then you're join is incorrect.
Chris
Regarding the edit - that's the doc for Drupal 7. Few are using Drupal 7, and the OP's code appears correct for D6 usage.
ceejayoz
@ceejayoz could you link the API for Drupal6 usage?
Chris
Swap 7 for 6. http://api.drupal.org/api/function/db_query_range/6
ceejayoz
@ceejayoz, that's what I thought. I don't see where Drupal6 allows for more than one parameter in `db_query_range` in that API.
Chris
@Chris, it allows for more than one, even if the function signature on top of the API doc suggests only one. See the parameter explanations a few lines down below. But you're still right in that he is telling Drupal to return 0 records, as he passes `$vid` as a query parameter substitution value, which is not used in his query, hence it will be interpreted as the 'from' parameter, using his $from value as the 'limit' parameter and ignoring his $query\_limit as superfluous cruft - perils of variable function arguments :/
Henrik Opel
Correction to my previous comment: The $from and $query\_limit parameters will be read correctly, but the unused $vid will cause the query parameter replacement logic to trip - he should have found plenty of mysql errors in his logs :/
Henrik Opel
A: 

Have you verified that any nodes in your Drupal install have a taxonomy term from the #1 taxonomy vocabulary? Your query will result in zero rows if the #1 vocabulary is not used in any nodes.

ceejayoz
the queries are working in phpmyadmin but not working in drupal, no idea why
pmarreddy
That doesn't make any sense. Can you provide more code context, because if the two are giving different results it's almost certainly a coding error somewhere.
ceejayoz
i figured out the problem is with the no of rows or the query limit in drupal which is working for less than 100, can somebody tell me how to solve this problem in drupal
pmarreddy
+2  A: 

Given your example, you do not pass the right parameters to db_query_range. You should either try without passing the unused query parameter substitution $vid:

$query_limit = 190;
$query1 = "SELECT N.nid ,N.tid FROM term_node N JOIN term_data S ON S.tid = N.tid AND S.vid = 1";
$query_result = db_query_range($query1, 0, $query_limit);

or better, use it properly by referencing it in your query (the %d at the end of your query will get substituted by the value of $vid:

$vid = 1;
$query_limit = 190;
$query1 = "SELECT N.nid ,N.tid FROM term_node N JOIN term_data S ON S.tid = N.tid AND S.vid = %d";
$query_result = db_query_range($query1, $vid, 0, $query_limit);
Henrik Opel
thanks but it still dint solve the problem, if i put the query to 400 it is giving be blank screen
pmarreddy
Well, it sounds like you got two different problems mixed up here - I guess the limit problem should best be discussed at your new question under http://stackoverflow.com/questions/1528094/query-limit-issue-with-php-and-mysql-drupal-6
Henrik Opel