Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 10    Views: 60

@rob
Code is Art
Profile
Posts: 115
Reg: Dec 10, 2013
Alabama
8,800
01/06/14 11:35 AM (11 years ago)

PHP help

I seem to be so close but just can't figure out the last step. I have an iOS app using the "simple menu" plugin driven by a data url which points to a custom php script. The PHP script queries my database, converts the query results to json and build the menu just as expected. The menu is a list of mp3 titles (the actual mp3 files are located in a directory on the local server). I want the menu button when tapped to load the "BTA AudioStreamer" screen and populate it with the correct MP3 file. Everything is working as expected, the menu builds correctly and when I tap a button, the "BTA AudioStremer" screen loads. My problem is, how do I pass all the correct info about the MP3 file to the "BTA AudioStreamer" screen. I am somewhat new to PHP but here are my files: This one grabs the data form my db, converts it to json and populates my menu: <?php require_once("/home/content/32/10420832/html/BT-server/config.php"); //set content type for HTML Document header("Content-Type: text/plain; charset=utf-8"); //start json variable $json .= "{"; //start child items $json .= ""childItems":["; //go to database...get stuff form sermon table $strSql = "SELECT * FROM sermons ORDER BY sermon_date DESC "; //use built in php scripts from existing BR scripts on my Self Hosted Server $res = fnDbGetResult($strSql, APP_DB_HOST, APP_DB_NAME, APP_DB_USER, APP_DB_PASS); //loop through query results $cnt = 0; if($res){ $numRows = mysql_num_rows($res); if($numRows > 0){ while($row = mysql_fetch_array($res)){ $cnt++; $json .= "{"; $json .= ""itemId":"" . $row["id"] . "","; $json .= ""itemType":"Bt_menuItem","; $json .= ""titleText":"" . $row["title"] . " - " . date("M d, Y",strtotime($row['sermon_date'])) . "","; $json .= ""loadScreenWithItemId":"159FCE2422882B60A620FEB""; $json .= "}"; //add coma if not the last item if($cnt < $numRows){ $json .= ","; } }//close while loop }//close if numRows }//end if res //end json variable $json .= "]}"; //print output echo $json; //exit exit(); ?> This next one I wrote just to grab all the data needed for the "BTA AudioStreamer" plugin and convert it to json in the format needed by the "BTA AudioStreamer" plugin (the problem is I dont know how to pass this data on the "BTA AudioStreamer" screen from my menu screen: <?php require_once("/home/content/32/10420832/html/BT-server/config.php"); //set content type for HTML Document header("Content-Type: text/plain; charset=utf-8"); //go to database...get stuff form sermon table $strSql = "SELECT * FROM sermons ORDER BY sermon_date DESC "; //use built in php scripts from existing BR scripts on my Self Hosted Server $res = fnDbGetResult($strSql, APP_DB_HOST, APP_DB_NAME, APP_DB_USER, APP_DB_PASS); //loop through query results $cnt = 0; if($res){ $numRows = mysql_num_rows($res); if($numRows > 0){ while($row = mysql_fetch_array($res)){ $cnt++; $json .= "{"; $json .= ""itemId":"" . $row["id"] . "","; $json .= ""itemType":"BTA_audiostreamer","; $json .= ""itemNickname":"","; $json .= ""myStreamUrl":"/files/custom/" . $row["file_name"] . "","; $json .= ""streamTitle":" . $row["title"] . "","; $json .= ""streamDescription":"" . $row["sermon_title"] . "","; $json .= ""albumURL":"/files/custom/sermon-icon.png","; $json .= ""myScrollText":"" . $row["title"] . " - " . date("M d, Y",strtotime($row['sermon_date'])) . "","; $json .= ""navBarTitleText":"","; $json .= ""navBarStyle":"hidden","; $json .= ""backgroundImageURLSmallDevice":"","; $json .= ""backgroundImageURLLargeDevice":"","; $json .= ""titleText":"" . $row["title"] . " - " . date("M d, Y",strtotime($row['sermon_date'])) . "","; $json .= ""loadScreenWithItemId":"159FCE2422882B60A620FEB""; $json .= "}"; //add coma if not the last item if($cnt < $numRows){ $json .= ","; } }//close while loop }//close if numRows }//end if res //print output echo $json; //exit exit(); ?>
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/06/14 12:42 PM (11 years ago)
Better would be to have one script that does it all. Something like this: $json .= "{"; $json .= "\"itemId\":\"" . $row["id"] . "\","; $json .= "\"itemType\":\"Bt_menuItem\","; $json .= "\"titleText\":\"" . $row["title"] . " - " . date("M d, Y",strtotime($row['sermon_date'])) . "\","; $json .= "\"loadScreenObject\":{"; //details for mp3 file $itemId = $row['id']; $thisURL = "/files/custom" . $row['file_name']; $thisTitle = $row['title']; $thisDesc = $row['sermon_title']; $json .= "\"itemId\":\"$itemId\","; $json .= "\"itemType\":\"BTA_audiostreamer\","; $json .= "\"myStreamUrl\":\"$thisURL\","; $json .= "\"streamTitle\":\"$thisTitle\","; $json .= "\"streamDescription\":\"$thisDesc\","; (...etc...) $json .= "}";
 
@rob
Code is Art
Profile
Posts: 115
Reg: Dec 10, 2013
Alabama
8,800
like
01/06/14 12:46 PM (11 years ago)
yep, I thought the solution would be just a single php script, just wasn't sure how to go about combining them together (still learning php), thanks for pointing me in the right direction @chris1. I will tinker with this and post back my results...I also see the loadScreenObject reference, I had missed that as well
 
@rob
Code is Art
Profile
Posts: 115
Reg: Dec 10, 2013
Alabama
8,800
like
01/06/14 01:40 PM (11 years ago)
@chris1...everything looks valid and I ran my json through the json validator and it checks out but I get an Error when I run my app (Simple Menu) in the simulator telling me the json may not be well formed. Do you see anything offensive jumping out at you from this snippet: **FYI, I added the linebreaks to make it easier to read** { "childItems":[ { "itemId":"167", "itemType":"Bt_menuItem", "titleText":"The Life of Thankfulness - Dec 15, 2013", "loadScreenObject": { "itemId":"167", "itemType":"BTA_audiostreamer", "itemNickname":"", "myStreamUrl":"/files/custom/sermons/12_15_13.mp3", "streamTitle":"The Life of Thankfulness", "streamDescription":"", "albumURL":"/files/custom/sermon-icon.png", "myScrollText":"The Life of Thankfulness - Dec 15, 2013", "navBarTitleText":"", "navBarStyle":"hidden", "backgroundImageURLSmallDevice":"", "backgroundImageURLLargeDevice":"", "loadScreenWithItemId":"159FCE2422882B60A620FEB" } }, { "itemId":"166", "itemType":"Bt_menuItem", "titleText":"Deception in the Church (Vol 4) - Dec 08, 2013", "loadScreenObject": { "itemId":"166", "itemType":"BTA_audiostreamer", "itemNickname":"", "myStreamUrl":"/files/custom/sermons/12_8_13.mp3", "streamTitle":"Deception in the Church (Vol 4)", "streamDescription":"", "albumURL":"/files/custom/sermon-icon.png", "myScrollText":"Deception in the Church (Vol 4) - Dec 08, 2013", "navBarTitleText":"", "navBarStyle":"hidden", "backgroundImageURLSmallDevice":"", "backgroundImageURLLargeDevice":"", "loadScreenWithItemId":"159FCE2422882B60A620FEB" } } ] }
 
@rob
Code is Art
Profile
Posts: 115
Reg: Dec 10, 2013
Alabama
8,800
like
01/06/14 01:46 PM (11 years ago)
@chris1...everything looks valid and I ran my json through the json validator and it checks out but I get an Error when I run my app (Simple Menu) in the simulator telling me the json may not be well formed. Do you see anything offensive jumping out at you from this snippet: **FYI, I added the linebreaks to make it easier to read** { "childItems":[ { "itemId":"167", "itemType":"Bt_menuItem", "titleText":"The Life of Thankfulness - Dec 15, 2013", "loadScreenObject": { "itemId":"167", "itemType":"BTA_audiostreamer", "itemNickname":"", "myStreamUrl":"/files/custom/sermons/12_15_13.mp3", "streamTitle":"The Life of Thankfulness", "streamDescription":"", "albumURL":"/files/custom/sermon-icon.png", "myScrollText":"The Life of Thankfulness - Dec 15, 2013", "navBarTitleText":"", "navBarStyle":"hidden", "backgroundImageURLSmallDevice":"", "backgroundImageURLLargeDevice":"", "loadScreenWithItemId":"159FCE2422882B60A620FEB" } }, { "itemId":"166", "itemType":"Bt_menuItem", "titleText":"Deception in the Church (Vol 4) - Dec 08, 2013", "loadScreenObject": { "itemId":"166", "itemType":"BTA_audiostreamer", "itemNickname":"", "myStreamUrl":"/files/custom/sermons/12_8_13.mp3", "streamTitle":"Deception in the Church (Vol 4)", "streamDescription":"", "albumURL":"/files/custom/sermon-icon.png", "myScrollText":"Deception in the Church (Vol 4) - Dec 08, 2013", "navBarTitleText":"", "navBarStyle":"hidden", "backgroundImageURLSmallDevice":"", "backgroundImageURLLargeDevice":"", "loadScreenWithItemId":"159FCE2422882B60A620FEB" } } ] }
 
@rob
Code is Art
Profile
Posts: 115
Reg: Dec 10, 2013
Alabama
8,800
like
01/06/14 01:48 PM (11 years ago)
just wondering should there be quotes before/after the array brackets for the loadSreenObject like this "loadScreenObject": "{ "itemId":"167", "itemType":"BTA_audiostreamer", "itemNickname":"", "myStreamUrl":"/files/custom/sermons/12_15_13.mp3", "streamTitle":"The Life of Thankfulness", "streamDescription":"", "albumURL":"/files/custom/sermon-icon.png", "myScrollText":"The Life of Thankfulness - Dec 15, 2013", "navBarTitleText":"", "navBarStyle":"hidden", "backgroundImageURLSmallDevice":"", "backgroundImageURLLargeDevice":"", "loadScreenWithItemId":"159FCE2422882B60A620FEB" }"
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/06/14 01:50 PM (11 years ago)
@Rob: Turn on your email in here so I can send you a message or send me one...sorry for the post highjack! LA
 
@rob
Code is Art
Profile
Posts: 115
Reg: Dec 10, 2013
Alabama
8,800
like
01/06/14 01:54 PM (11 years ago)
hey @LA, I just turned on messaging "I didn't realize I had it off"
 
@rob
Code is Art
Profile
Posts: 115
Reg: Dec 10, 2013
Alabama
8,800
like
01/06/14 03:47 PM (11 years ago)
just wondering should there be quotes before/after the array brackets for the loadSreenObject like this "loadScreenObject": "{ "itemId":"167", "itemType":"BTA_audiostreamer", "itemNickname":"", "myStreamUrl":"/files/custom/sermons/12_15_13.mp3", "streamTitle":"The Life of Thankfulness", "streamDescription":"", "albumURL":"/files/custom/sermon-icon.png", "myScrollText":"The Life of Thankfulness - Dec 15, 2013", "navBarTitleText":"", "navBarStyle":"hidden", "backgroundImageURLSmallDevice":"", "backgroundImageURLLargeDevice":"", "loadScreenWithItemId":"159FCE2422882B60A620FEB" }"
 
@rob
Code is Art
Profile
Posts: 115
Reg: Dec 10, 2013
Alabama
8,800
like
01/06/14 03:49 PM (11 years ago)
@chris1 thanks so much for pointing me in the right direction, I finally have this working (at least using a flat text file for the data) so all I have to do now is get the json syntax sorted out in my script which shouldn't be a big deal now that I know that it works if it gets properly formatted json....THANKS again!!
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/06/14 03:51 PM (11 years ago)
no problem - glad to help :)
 

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.