matthewvanb Posted October 4, 2008 Share Posted October 4, 2008 About the App: It's a Podcast management system (based with a mysql and XML database), and for the editing section of the RSS feed, I list all the titles of the podcasts on a page, and pass the array index as the URL parameter to the actual editing page. What i'm trying to-do now is to use the $_GET variable thats passed and use it as the array index (for the XML) so I can grab the podcast information from that specific podcast. index.php <?php $rss=simplexml_load_file('../podcastFeed.xml'); $count = 0; foreach($rss->channel->item as $item) { echo "<p><a href='edit.php?id=".$count."'>".$item->title."</p>"; $count++; } ?> edit.php <?php //make sure that the $_GET[''] isn't empty if(!isset($_GET['id'])) { header('Location: index.php'); } else { $xml_id= $_GET['id']; //PASS THE $xml_id as the array index $index = ....??? $rss = simplexml_load_file('../podcastFeed.xml'); $title = $rss->channel->item[$index]->title; $pubDate = $rss->channel->item[$index]->pubDate; $author = $rss->channel->item[$index]->author; $description = $rss->channel->item[$index]->description; $guid = $rss->channel->item[$index]->guid; } anyone mind giving me a helping hand with this? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/127060-solved-passing-a-_get-variable-as-an-array-index/ Share on other sites More sharing options...
genericnumber1 Posted October 4, 2008 Share Posted October 4, 2008 Why can't you just use it directly? $title = $rss->channel->item[$xml_id]->title; Quote Link to comment https://forums.phpfreaks.com/topic/127060-solved-passing-a-_get-variable-as-an-array-index/#findComment-657270 Share on other sites More sharing options...
matthewvanb Posted October 4, 2008 Author Share Posted October 4, 2008 opps... sorry for the mis print $id = $_GET['id']; $rss = simplexml_load_file('../podcastFeed.xml'); $title = $rss->channel->item[$id]->title; $pubDate = $rss->channel->item[$id]->pubDate; $author = $rss->channel->item[$id]->author; $description = $rss->channel->item[$id]->description; $guid = $rss->channel->item[$id]->guid; even when I do that, I still get no results back... Quote Link to comment https://forums.phpfreaks.com/topic/127060-solved-passing-a-_get-variable-as-an-array-index/#findComment-657288 Share on other sites More sharing options...
genericnumber1 Posted October 4, 2008 Share Posted October 4, 2008 Ah, well I don't use simplexml, I can't help you there Quote Link to comment https://forums.phpfreaks.com/topic/127060-solved-passing-a-_get-variable-as-an-array-index/#findComment-657289 Share on other sites More sharing options...
matthewvanb Posted October 5, 2008 Author Share Posted October 5, 2008 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/127060-solved-passing-a-_get-variable-as-an-array-index/#findComment-657304 Share on other sites More sharing options...
genericnumber1 Posted October 5, 2008 Share Posted October 5, 2008 try doing var_dump($rss), it may help you see what the problem is. Also try enabling E_NOTICE, it will tell you if you're addressing a variable that isn't set. Quote Link to comment https://forums.phpfreaks.com/topic/127060-solved-passing-a-_get-variable-as-an-array-index/#findComment-657331 Share on other sites More sharing options...
matthewvanb Posted October 5, 2008 Author Share Posted October 5, 2008 Here's what I got from the var_dump: object(SimpleXMLElement)#1 (2) { ["@attributes"]=> array(1) { ["version"]=> string(3) "2.0" } ["channel"]=> object(SimpleXMLElement)#3 (7) { ["title"]=> string(27) "New Life Foursquare Podcast" ["link"]=> string(24) "http://podcasts.nlfe.org" ["description"]=> string(55) "A podcast of the weekly sermons at New Life Foursquare." ["lastBuildDate"]=> string(31) "Mon, 10 Mar 2008 11:34:25 -0700" ["language"]=> string(2) "en" ["image"]=> object(SimpleXMLElement)#4 (3) { ["url"]=> string(48) "http://podcasts.nlfe.org/images/nlfePodcast.jpeg" ["title"]=> string(27) "New Life Foursquare Podcast" ["link"]=> string(24) "http://podcasts.nlfe.org" } ["item"]=> array(24) { [0]=> object(SimpleXMLElement)#2 (5) { ["title"]=> string(41) "Humility: Bowing Low (Summer Focus Pt. 6)" ["pubDate"]=> string(15) "August 03, 2008" ["author"]=> string(10) "Mattie Poo" ["description"]=> string(39) "Weekly Podcast from New Life Foursquare" ["guid"]=> string(57) "http://podcasts.nlfe.org/podcastFiles/summerfocus_pt6.mp3" } .......... } } } Which is what it should look like, and it looks like my codes getting what it should... unless I need to be passing two parameters through the GET variable... I tried using the E_NOTICE but got nothing back.. Quote Link to comment https://forums.phpfreaks.com/topic/127060-solved-passing-a-_get-variable-as-an-array-index/#findComment-657347 Share on other sites More sharing options...
genericnumber1 Posted October 5, 2008 Share Posted October 5, 2008 edit: that's odd, try replacing $id with 0 to see if you can address it like that... Quote Link to comment https://forums.phpfreaks.com/topic/127060-solved-passing-a-_get-variable-as-an-array-index/#findComment-657349 Share on other sites More sharing options...
matthewvanb Posted October 5, 2008 Author Share Posted October 5, 2008 okay I got it! When passing it through the GET variable, it passed the number as a string, which the array index couldn't take, So I used the intval function then to convert that string, into the int which the array index can take, and then it works perfectly! thanks for all your help and suggestions! Quote Link to comment https://forums.phpfreaks.com/topic/127060-solved-passing-a-_get-variable-as-an-array-index/#findComment-657354 Share on other sites More sharing options...
genericnumber1 Posted October 5, 2008 Share Posted October 5, 2008 that is odd that it wouldn't convert it from a string to an int automatically, but eh, if it works glad you got it working. Quote Link to comment https://forums.phpfreaks.com/topic/127060-solved-passing-a-_get-variable-as-an-array-index/#findComment-657355 Share on other sites More sharing options...
matthewvanb Posted October 5, 2008 Author Share Posted October 5, 2008 ya, one would figure. Quote Link to comment https://forums.phpfreaks.com/topic/127060-solved-passing-a-_get-variable-as-an-array-index/#findComment-657356 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.