By l_d on
Hi,
I'm having some trouble with telling the Argument Code box to do what I want. I can select a single row from the database, but I can't work out how to get multiple rows back and add them to the $args array. I'd like the results of the SQL query to determine which nodes are displayed.
This is working and returning back 1 result:
if (arg(0) == 'node' && is_numeric(arg(1))) {
$sql = "SELECT field_tag_artist_nid FROM {content_field_tag_artist} WHERE nid = %d";
$args[0] = db_result(db_query($sql, arg(1)));
}
return $args;
This doesn't display any content at all in the view:
if (arg(0) == 'node' && is_numeric(arg(1))) {
$sql = "SELECT field_tag_artist_nid FROM {content_field_tag_artist} WHERE nid = %d";
$results = db_query($sql, arg(1))
while($row = db_fetch_array($results)) {
$args[] = $row
}
}
return $args;
Can somebody point me in the right direction?
Thanks,
Luke
Comments
Does it work when $args[] =
Does it work when
$args[] = $rowis replaced with
$args[] = $row[0];?
----
input#edit-delete { margin-left: 4em;}
No, I still get nothing.
No, I still get nothing. Good suggestion though. I also get nothing if I try
SELECT *and$row[3], which is the column thefield_tag_artist_nidis in.For Argument Type I've selected Node: ID, I'm not sure if that affects anything. I don't understand the Argument Code logic, but I've spent a couple of days trying to find information online and trying things out.
$results = db_query($sql,
?
In other words, we should pass the following array: ('or', 'nid1', 'nid2', 'nid3'...)
--
input#edit-delete { margin-left: 4em;}
Thanks for your help, still
Thanks for your help, still no luck though. My code looked like this after your suggestion:
I also tried
$args[0][] = $row[0]and$args[0][] = $rowbut still nothing is showing up yet. There should be two nodes that display.Thanks.
Try to insert print_r
Try to insert
print_r ($args);before the return statement. This will print the contents of $args array. Post it here.
--
input#edit-delete { margin-left: 4em;}
print_r() doesn't seem to
print_r()doesn't seem to cause anything print to screen. I tried manually assigning a value to the$argsarray before it and that didn't print anything either, so it's not because$argswas blank. I'd really like to know how to debug within the Argument Code box to see what's going on! Is there any other way Drupal could print a variable dump from code in the Argument Code box?Hmm .. which is strange
Hmm .. which is strange because #36 of http://www.lullabot.com/audiocast/podcast-50-drupal-tips-and-tricks seems to say that
print_r()should work. I'm making this view for a block, but even ticking Page, assigning the view a URL and viewing it there, I still get nothing back from puttingprint_r($args);in the Argument Code.Replace your Arguments
Replace your Arguments handling code with
print_r($view). Does that show anything?--
input#edit-delete { margin-left: 4em;}
Still nothing :). I'm
Still nothing :). I'm looking at
$view->filterhttp://drupal.org/node/86410#comment-631383
As some kind of way of selecting? I'm just clutching at straws at this point. It produces a nice SQL error so at least it's trying something...
Okay, I'm now looking at a
Okay, I'm now looking at a thread
http://lists.drupal.org/pipermail/support/2007-March/004316.html
http://lists.drupal.org/pipermail/support/2007-March/004319.html
http://lists.drupal.org/pipermail/support/2007-March/004321.html
and it seems the way I understood the $args was all wrong. Which sadly still doesn't help me much. I've realised the reason why I'm struggling is because the table I'm wanting to select from, I'm effectively needing to do a look up in reverse from what Drupal seems to want me to do.
Drupal uses the arguments to create a WHERE condition, except the SQL statement returns the 'nid' values, whereas in this situation I'm wanting to return the field_tag_artist_nid values. I wonder if I can get Drupal to do this at all? If all else fails I'll try directly hacking my code into the template.