By publetariat on
How can I alter this snippet of php so it returns ALL records from the specified table, instead of just the first one? What I need in the resultset is an array of ALL nid values from the specified table.
$result = db_fetch_array(db_query('SELECT nid FROM vault_lm_paypal_subscribers'));
return array($result['nid']);
Thanks in advance for any assistance... =')
Comments
$nids = array();$result =
THANK YOU SOOOOOOO MUCH!!!!
nevets -
I've been struggling with this view problem for days, and in one fell post you've solved it for me! Your query works perfectly.
For others reading this - I needed this query to use with the LM PayPal Paid Adverts & Views PHP Filter modules. LM Paypal Paid Adverts allows you to set desired node types as requiring payment to be "published", but not "published" in the Drupal node sense---"published" in the sense that a status flag is set to true in one of LM PayPal's tables, and other code in the module makes the node visible as a result. I need to display a list of paid nodes in a view, but this isn't natively possible since the LM PayPal Paid Adverts tables aren't available to Views, and LM PayPal Paid Adverts doesn't alter the contents of any tables that ARE available to Views.
However, that 'paid' status flag is in the lm_paypal_subscribers table, which also includes node id# (field 'nid'). Since nid is also part of the data set returned by a basic node-type view, I knew if I could somehow access lm_paypal_subscribers from within my view I could filter the records based on paid status. Searching for options to get at that table in a view, I found and installed the Views PHP Filter module, which allows you to filter Views content based on a PHP snippet. I figured I'd create a view with all the node information I wanted in it, then use Views PHP Filter to filter the list of nodes based on a SQL query that pulled the node IDs (nid field) from the lm_paypal_subscribers table.
But try as I might, I couldn't get my PHP snippet right; it just kept returning the first row of lm_paypal_subscribers, even using functions other than db_fetch_array.
So nevets, you're my hero! I'm going to add this to the support areas for both Views PHP Filter and LM PayPal Adverts.