Note that there are some explanatory texts on larger screens.

plurals
  1. POAdditional arguments in my php class
    primarykey
    data
    text
    <p>I'm trying to add a new variable (argument) `$sugg_only = false' to the get_lists method. Right now I'm pulling all my data based on if the user has a sign in token. This works fine and returns the array of data on their custom list. </p> <p>What I'm trying to do is return stuff from their shopping_list_name if the Suggested column is set to <code>Y</code>. This way if they don't have a custom list it will pull a suggested list that we provide. </p> <p>Here’s the full list of what’s in the table:</p> <pre><code>ID SHOPPING_LIST_NAME S SEQUENCE </code></pre> <hr> <pre><code> 1 test amnaik shopping list N 2 bonner shopping list N 3 793d7384fa4fa247d6fae07db104147d0a2dad6e Y 4 kj's shopping list N 5 kj's shopping list from 1384201636 N 6 kj's shopping list from 1384201659 N 7 kj's shopping list from 1384202055 N 8 kj's shopping list from 1384202089 N 9 kj's shopping list from 1385064064 N 10 kj's shopping list from 1385064145 N 11 kj's shopping list from 1385064150 N 12 kj's shopping list from 1385064257 N 13 kj's shopping list from 1385064825 N 14 kj's shopping list from 1385064857 N </code></pre> <p>So, as you see, there’s just one (terribly named) shopping list that’s setup as a suggestion.</p> <pre><code>// Get a user's shopping lists public function get_lists($clobber = false, $sugg_only = false) { if ($this-&gt;UserShoppingList != null &amp;&amp; !$clobber) { return $this-&gt;UserShoppingList; } else if ($this-&gt;get_sign_in_token()) { global $db; $vars = array(); $vars[] = array(':i_sign_in_token', strtoupper($this-&gt;get_sign_in_token())); $rows = $db-&gt;get_function_ref_cursor('custom.japi_shopping_list.get_lists_for_shopper(:i_sign_in_token)', $vars); // Turn the rows into objects and get their items. foreach ($rows as $row) { $list = new UserShoppingList(null, $this-&gt;sign_in_token); $list-&gt;get_from_array($row); $list-&gt;get_items(); $this-&gt;UserShoppingList[] = $list; } return $this-&gt;UserShoppingList; } else { return false; } } </code></pre> <p>api page:</p> <pre><code> if(!isset($_GET['token']) &amp;&amp; !isset($_GET['suggested_only'])) { die('Must pass-in either a \'token\' or \'suggested_only\' flag'); } if(isset($_GET['token'])) { $shopper = new Shopper($_GET['token']) or die('Could not instantiate a new Shopper from the \'token\' passed-in'); $array = array(); $shopper_lists = $shopper-&gt;get_lists(true); foreach ($shopper_lists as $list) { $array[] = $list-&gt;json(); } echo json_encode($array); // echo json_encode($shopper_lists); } </code></pre> <p>Will i likely be writing another <code>foreach</code> loop and just including whatever happens if $sugg_only is equal to TRUE??</p> <p>add something like so to the bottom of my api page??:</p> <pre><code>if(isset($_GET['suggested_only']) &amp;&amp; $_GET['suggested_only'] == 'true') { } </code></pre> <p>Any help would be greatly appreciated. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload