To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Coding

Coding Help with PHP coding

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-03-2009, 07:57 PM   #1
kamy99
Senior Member
 
kamy99's Avatar
 
Join Date: May 2002
Posts: 288
resolved [RESOLVED] How to filter XMl result?

I have an XML file that lists all the services I provide to my customers.

I can populate a list from this file easily.
What I'd like to do is when someone clicks on a particular service, then I display the description of that particular service.
I think I need to use xpath, but not sure how....

My xml file look like this:
Code:
<services>

<service >
<id>1</id>
<title>Website Design and Programming </title>
<desc>blah blah </desc>
</service>

<service >
<id>2</id>
<title>Database Programming </title>
<desc>wrfwrfwrf </desc>
</service>

<service >
<id>3</id>
<title>Web Development (PHP, XHTML, JavaScript, CSS, AJAX)</title>
<desc>some text </desc>
</service>
</services>
PHP code to display a list of all services:

Code:
<ul>
<? 
	$Data=simplexml_load_file('services.xml');
	foreach ($Data->service as $service)
	{
	
foreach ($service->id as $id)
	{
	foreach ($service->title as $title)
	{
	?>
  <li><a href="display.php?Service=<? echo $id;?>" title="<? echo $title;?>"><? echo $title;?></a></li>
   <? }	} }?>
</ul>
On the display page I only want to show the description of the service that's been clicked.

Eventually I'd like to use jquery ajax call to load the description on the same page , but that's another story

Help is greatly appreciated, tx, kamy
__________________
I always need money!
I am from the Athletic Republic of Soccer
kamy99 is offline   Reply With Quote
Old 11-04-2009, 12:48 PM   #2
scrupul0us
I see what you did there
 
Join Date: Sep 2004
Location: Albany, NY
Posts: 1,621
you can do it easily with xpath... I don't have my "toolbox" in front of me at the moment but I can find some examples later if you cant figure it out
__________________
***If your problem has been solved, PLEASE click the RESOLVED LINK under "Thread Tools"***

Buy Chris Shiflett's Book Essential PHP Security

Dev Server: Apache 2.2.x | PHP 5.2.6 | MySQL 5.x

PHP Manual | Learn HTML | Validate HTML
scrupul0us is offline   Reply With Quote
Old 11-04-2009, 12:55 PM   #3
scrupul0us
I see what you did there
 
Join Date: Sep 2004
Location: Albany, NY
Posts: 1,621
PHP Code:
$container = $Data->query("parent:://id[contains(.,'"$_GET['id']"')]");
echo
$container->description->nodeValue;
something roughly along those lines
__________________
***If your problem has been solved, PLEASE click the RESOLVED LINK under "Thread Tools"***

Buy Chris Shiflett's Book Essential PHP Security

Dev Server: Apache 2.2.x | PHP 5.2.6 | MySQL 5.x

PHP Manual | Learn HTML | Validate HTML
scrupul0us is offline   Reply With Quote
Old 11-05-2009, 12:02 AM   #4
kamy99
Senior Member
 
kamy99's Avatar
 
Join Date: May 2002
Posts: 288
Thanks, that certainly helped greatly!

I achieved it with a foreach loop.

Code:
$Data=simplexml_load_file('services.xml');
	
	$result = $Data->xpath('/services/service[id='.$_GET["Service"].']');
 
	foreach ($result as $desc)
	{
	echo "<div id=ServiceTitle>".$desc->title."</div>"; 
	echo "<div id=ServiceDesc>".$desc->desc."</div>";
  }
What you think?
__________________
I always need money!
I am from the Athletic Republic of Soccer
kamy99 is offline   Reply With Quote
Old 11-05-2009, 08:31 AM   #5
scrupul0us
I see what you did there
 
Join Date: Sep 2004
Location: Albany, NY
Posts: 1,621
There ya go... =)
__________________
***If your problem has been solved, PLEASE click the RESOLVED LINK under "Thread Tools"***

Buy Chris Shiflett's Book Essential PHP Security

Dev Server: Apache 2.2.x | PHP 5.2.6 | MySQL 5.x

PHP Manual | Learn HTML | Validate HTML
scrupul0us is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 04:54 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.