Jump to content

Matching xml data to database


graham23s

Recommended Posts

Hi Guys,

 

What i'm trying to do is pull from and xml file and loop from the database, if 2 codes match then perform an action.

 

code:

 

<?php
include("inc/inc-dbconnection.php");

$call_url = 'http://www.site.com/load_xml.php?id=15320&subid=&geoip='.$user_ip;
$xml = simplexml_load_file($call_url);


//START Simple Output
foreach($xml->offer as $offers) 
{
	$c1 = $offers->country;		
	$q = mysql_query("SELECT * FROM `cpa_country_codes`");

	while ($r = mysql_fetch_array($q))
	{
	$c2 = $r['code_country'];

        if ($c1 == $c2)
        {
        
         //Perform action
        
        }

	}
}	 

?>

 

This is what i have concocted so far.

 

any help would be appreciated

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/190443-matching-xml-data-to-database/
Share on other sites

You are missing one of the main points of using a database, let the database engine find the data you want.

 

You should be using a WHERE clause in your query and then testing if the query returned a matching row. Your query should be something like this -

 

"SELECT * FROM cpa_country_codes WHERE code_country = '$c1'"

Archived

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

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