Jump to content

Archived

This topic is now archived and is closed to further replies.

dustinto

Creating a dynamic page ?id=

Recommended Posts

I have info stored in an XML file and I want to parse it to a dynamic page (page.php?id={id})

XML file is setup like

<category id="something" name="name" address="bahh"...etc>
<category id="something" name="name" address="bahh"...etc>
<category id="something" name="name" address="bahh"...etc>

I don't want the data to be put into a table (like most XML stuff seems to do). I think I know how to get all this to work I just need help getting the dynamic part of the page to work.

I am guessing I am going to need some type of if statement, but I don't know where to start.

(if anyone knows of a good web site/tutorial on this that would be great.)

Thanks in advance

Share this post


Link to post
Share on other sites
Not too clear on your post... can you give more examples, etc?

Share this post


Link to post
Share on other sites
Well, assuming that your file is setup

<category id="something" name="name" address="bahh"...etc>
<category id="something" name="name" address="bahh"...etc>
<category id="something" name="name" address="bahh"...etc>

with each <category /> on a separate line then you could read the contents of it like this:

[code]
<?php

$file = file("file.xml");
if (is_array($file)) {
  while(list($key,$val)=each($file)) {
    if ( strtolower(substr(trim($val), 0, 9)) == "<category" ) {
      $start = strpos($val, "id=\"")+4;
      $end = strpos($val, "\"", $start);
      $id[$key] = substr($val,  $start, $end);
      $start = strpos($val, "name=\"")+6;
      $end = strpos($val, "\"", $start);
      $name[$key] = substr($val, $start, $end);
      $start = strpos($val, "address=\"")+9;
      $end = strpos($val, "\"", $start);
      $addres[$key] = substr($val, $start, $end);
    }
  }
}

?>
[/code]

This still leaves a lot of room for error and may need to be adjusted slightly on where it begins and ends extracting your values, but this will give you the basic idea. I have not tested this code, it is just what I wrote on the fly, but it should do what you are looking for if I am not mistaken. It is supposed to give you three arrays which you can then sort in any manner you like and manipulate. If you need help with the manipulation or output of the arrays in some format, I would be happy to help.

Happy coding!

Share this post


Link to post
Share on other sites

×

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.