I have this code here to print from the first five records in node 10 and put them on my front page. The problem is, it is printing ALL records from node 10. What do I need to do?

 $sql = "SELECT * FROM {node} n, {node_revisions} r WHERE n.nid=10 AND r.nid=10 AND n.status=1";
					$result = db_query_range(db_rewrite_sql($sql), 0, 5);
						while ($myNode = db_fetch_object($result)) {
						  echo $myNode->body;
	   		}

Comments

nevets’s picture

Nodes are a "single" record which may have revisions. So normally there is only active/current instance of a given node. To load a single node one would normally use something like

$node  = node_load(10);

So what do you consider a record?

Anything-1’s picture

What I meant was...in node 10, I have a list of items

  • . I want the first five to print on the front page. Is there any way I can do this? I was thinking the wrong thing. Thanks
jaypan’s picture

Your usage of db_query_range() is correct, but your query is wrong. You are selecting the first 5 node revisions. The 'items' are obviously implemented from a custom content type, so you will have to look at where the data is stored in teh DB and re-write your sql to take the data from there.

Contact me to contract me for D7 -> D10/11 migrations.