Jump to content

[SOLVED] passing a $_GET variable as an array index


matthewvanb

Recommended Posts

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!

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.