Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 6    Views: 83

SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
01/20/13 06:40 PM (13 years ago)

PHP Format assistance request (loadScreenObject) : Solved

Hiya! I'm going nuts. A text file works, so my 'format' is right. I am trying to dynamically generate my JSON childItems list via PHP/MySQL, and can do so in an 'elementary' list. But I am not successful trying complex nested Json output. My examples are kind of long, so I've placed a pdf in my dropbox, if you wouldn't mind taking a look: <a href="https://dl.dropbox.com/u/115208762/PHPTrub.pdf" target="_blank" rel="nofollow">https://dl.dropbox.com/u/115208762/PHPTrub.pdf</a> It concerns creating another menu via "loadScreenObject", and the correct formatting of the PHP to create the childItems of that screen. If anyone can offer some guidance, I would greatly greatly appreciate it! Cheers! -- Smug
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
01/20/13 08:39 PM (13 years ago)
Holy cow, I got it to work (finally!) I've been wrestling with this for a couple of days now. The secret was a couple of fundamental goofs on my part. And I'm not entirely sure of everything I was doing wrong. But this is what my PHP File looks like now: if (mysql_num_rows($result) > 0) { $response["childItems"] = array(); while ($row = mysql_fetch_array($result)) { // temp user array $poi = array(); $poi["itemId"] = $row["recnum"]; $poi["itemType"] = "BT_menuItem"; $poi["titleText"] = $row["name"]; $poi["descriptionText"] = $row["desc"]; $poi["iconName"] = $row["icon"]; $poi["rowAccessoryType"] = "none"; // here is where I gather data from my database and put it // into an array for the loadScreenObject... $myRecNum = $row["recnum"]; $myName = $row["name"]; $myCat = $row["gcat"]; // Ok now I add them to an array, along with some static values... $myArray = array( 'itemID' => $myRecNum, 'itemType' => "WB_screen_menuImage", 'itemNickname' => $myCat, 'navBarTitleText' => $myCat, 'imageFileName' => 'http://www.myserver.com/banners/rotate.php', 'backgroundColor' => '#EDC9AF', 'includeAds' => '0', 'dataURL' => "http://www.myserver.com/recdetail.php?lat=[deviceLatitude]&lng=[deviceLongitude]&drec=$myRecNum" ); // then take your array give it to your screen object, NOT as JSON, but just as an array... $poi["loadScreenObject"] = $myArray; // add it to everything else as normal... array_push($response["childItems"], $poi); } // and then let PHP do the JSON encoding for you... echo json_encode($response); } else { // Records es Nada $response["success"] = 0; $response["message"] = "No products found"; echo json_encode($response); } Hope this helps someone save a little time... Cheers! -- Smug
 
Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
like
01/20/13 08:45 PM (13 years ago)
Appreciate you posting the answer... I always find I find the solution right after I post on the forums :P
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
01/20/13 09:03 PM (13 years ago)
I know, right!?! I figured Karma was just NOT going to let me discover the answer until I announced to the world I had a problem... lol! and of course, in hindsight, it makes 'perfect' sense NOW, but I was up a tree for a while... Cheers! -- Smug
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
01/21/13 07:39 AM (13 years ago)
very nice. Is this part of that random image script you posted not long ago? I wanted to look at that closer myself, I thought it was brilliant and had a couple of ideas to use it myself.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
01/21/13 01:48 PM (13 years ago)
This isn't that particular script; but I do use it for the "header image" for the menu_with_image plugin... I'll start collating my scripts and stick them in one spot for easy downloads... Cheers! -- Smug
 
Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
like
01/21/13 02:29 PM (13 years ago)
There should be an app for that :P
 

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.