Discussion Forums  >  Maps, Device Location, Tracking

Replies: 7    Views: 231

nickrick32
Apple Fan
Profile
Posts: 111
Reg: Feb 28, 2011
location unknow...
1,110
05/28/13 11:34 AM (11 years ago)

How to list only 20 items in this script?

Hi, I have this great David script for Maplocation or Menu items plugins which display all items from csv file based on location of the users mobile device. Now I need modification where it will not display all items from csv but only 20 items with the option to tap and load another 20 items. Another thing is when I call script (via menu items plugin) it show me last list which I have (because it is in cache of mobile device) and I need to refresh the list because if I'm in another location it show me last list and I have to refresh manually to get correct list for new destination. Can somebody help me with this? Thank you Here is the script. https://dl.dropboxusercontent.com/u/32338988/David_list_loc.php
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/28/13 03:37 PM (11 years ago)
In your script file, there are no line numbers, so you'll need to find this section, which is collecting all of your output for display (If your text editor has line numbers, it starts at line 328): ++++++++++++++++++++++++++++++ //Prepare to write the JSON output to the screen. header("Content-type: application/json"); //Loop through the childItems array and format the JSON echo "{\"childItems\":["; //for each item in the sorted array $parentCnt = 0; for($i = 0; $i < count($sortedArray); $i++){ +++++++++++++++++++++++++++++++++ On that last line that says: for($i = 0; $i < count($sortedArray); $i++){ Change it to say: for($i = 0; $i < 20; $i++){ and see how that works. Substitute '20' for whatever number should you decide. The basic explanation is, you don't *care* how many records are in the sorted array; you only want the first 20. Cheers! -- Smug
 
nickrick32
Apple Fan
Profile
Posts: 111
Reg: Feb 28, 2011
location unknow...
1,110
like
05/28/13 11:45 PM (11 years ago)
Hi Smug, I receive "There was an error parsing the JSON document. The document may not be well-formed." I get 20 listed items but JSON is not well formed.
 
nickrick32
Apple Fan
Profile
Posts: 111
Reg: Feb 28, 2011
location unknow...
1,110
like
05/29/13 12:21 AM (11 years ago)
I find what is the error instead of that //Don't print comma after last item.. if($parentCnt < count($sortedArray)){ echo ","; it need to be //Don't print comma after last item.. if($parentCnt < 20){ echo ","; and how to get last row to tap and get another 20 items?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/29/13 01:29 AM (11 years ago)
Good catch; I missed that. On the additional 20 items, I'm not sure. It would be 'easier' to provide a drop down box and let the user select 10/20/40/ALL locations, or something like that. Then you merely use a variable instead of a fixed number of records to return. Just a suggestion. Cheers! -- Smug
 
nickrick32
Apple Fan
Profile
Posts: 111
Reg: Feb 28, 2011
location unknow...
1,110
like
05/29/13 07:09 AM (11 years ago)
I saw that on a lot apps and I thinks this is the best way but how to get that? Also how to refresh page every time when request came from app?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/29/13 08:06 AM (11 years ago)
Well, if you want the page to refresh *every* time, you can set that in the HTML Plugin control panel. With respect to the user selecting the quantity of records, that is the million dollar question. It can be done in several ways, but it really depends on how 'you' are setting up your logic. The first question would be 'where' would be the place to insert that option. And on that page, or in that plugin, you would need to create the dropdown box, segmented button, whatever. You would assign the 'name' of the variable, and get the 'value' of the variable from the user form. If it's all in php, then in the page that determines the type of records being returned, add some kind of user selection for the number of records. <form action = "nextpage.php"> <!-- add a select box somewhere in your form --> <select name="recCount"> <option value="10">10 records</option> <option value="20">20 records</option> <option value="all">All records</option> </select> <!-- --> <input type="submit" value="Submit" /> </form> In your script that selects the records, you would use the variable name in place of the value, so that no matter 'which' value it is, your code can accommodate it. $myRecCount = GET["recCount"]; would be somewhere near the top of the php script, and if ($myRecCount="all") { $myRecCount = count($sortedarray); } else { // otherwise, just use the number that's there... } would go somewhere AFTER you have a value for sorted array. This is script off the top of my head with no testing, so use it as a guide, not a directive. Cheers! -- Smug
 
nickrick32
Apple Fan
Profile
Posts: 111
Reg: Feb 28, 2011
location unknow...
1,110
like
05/30/13 11:26 AM (11 years ago)
Hi Smug, Thank you I will try and let you know if it works.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.