What I want to achieve is that I want to return only 3 nodes from the Taxonomy term id which is given in the URL via the argument.

I put the following code, but it does not work

$args[] = arg(2);
$nids = array();
$myquery = db_query("SELECT nid FROM {term_node} WHERE tid = %d LIMIT 2", $args[]);
while ($row = db_fetch_array($myquery)) {
  $nids[] = $row['nid'];
}
return $nids;

But it results in error.
However when I put the exact term id ('689' is the term id) in the sql, it correctly returned me the nodes (for the following codes)

$nids = array();
$myquery = db_query("SELECT nid FROM {term_node} WHERE tid = '689' LIMIT 2");
while ($row = db_fetch_array($myquery)) {
  $nids[] = $row['nid'];
}
return $nids;

Can you give me some advice what was wrong with the argument passing?

Comments

heine’s picture

$myquery = db_query("SELECT nid FROM {term_node} WHERE tid = %d LIMIT 2", $args[]);

Should be

$myquery = db_query("SELECT nid FROM {term_node} WHERE tid = %d LIMIT 2", $args);

(or just use arg(2))

jaypan’s picture

$args[] = arg(2);

You are putting arg(2) into the $args array, and passing that array to your db_query. Pass arg(2) do db_query. Or remove the square brackets from $args[].

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