Jump to content

PHP and XML "database" trouble.


i73
Go to solution Solved by requinix,

Recommended Posts

Hey guys I am trying to read my xml file and itterate through the list. I am having trouble. 

<?xml version="1.0" encoding="UTF-8"?>
<stock>

	<itemPlace id="1">
		<name>null</name>
		<image>null</image>
		<wholeSale>44</wholeSale>
		<retailPrice>null</retailPrice>
		<quantity>null</quantity>
		<location>null</location>
		<color>null</color>
		<size>null</size>
		<weight>null</weight>
		<description>null</description>
		<itemType>null</itemType>
		<date>null</date>
	</itemPlace>
	<itemPlace id="2">
		<name>null</name>
		<image>null</image>
		<wholeSale>55</wholeSale>
		<retailPrice>null</retailPrice>
		<quantity>null</quantity>
		<location>null</location>
		<color>null</color>
		<size>null</size>
		<weight>null</weight>
		<description>null</description>
		<itemType>null</itemType>
		<date>null</date>
	</itemPlace>
</stock>
<?php 
		$xml = simplexml_load_file('stock.xml');
		foreach ($xml->xpath('itemPlace') as $eq) 
		{
			echo "<p><a class='inline' href=\"#inline_content\"> {$eq->name}</a></p>";
		    echo '<br>';
		    
		  	echo " <div style='display:none'>";
		   	echo " <div id='inline_content' style='padding:10px; background:#fff;'>";
		   	echo " <p>";
		    	
			echo "  <strong>{$eq->wholeSale}</strong>";
                        echo "</div></div>";

Is there a way I can look up the object through the itemPlace id="#" and call out the parameters of the item? Like the name price, etc?

 

I know how to mySQL query but not XML, and this is a project that needs to use xml... FML..I have been looking for a few hours so any help would be appreciated! :) 

Link to comment
Share on other sites

You can do a lookup with xpath:

foreach ($xml->xpath("//itemPlace[@id=123]") as $eq) // look for itemPlace with id=123
As for the "parameters", you're already doing it with $eq->wholeSale.

 

Thanks, yeah I realized as I fixed the problem.

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.