Jump to content

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'"

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.