Page 2 of 2

Posted: Tue Nov 08, 2005 9:46 am
by n00b Saibot
OK :D you are making it more complex than it really is :)

Code: Select all

$Update_Query = "UPDATE CB_rateplan SET <1> WHERE productid=<2>";

foreach($XML_IDList as $p_id) 
{ 
 if(in_array($p_id, $DB_IDList))
 { 
  foreach($columns as $i=>$col)
   if($i != 21) //avoid id field 
   $updlist[] = "$col='$temp[$i]'";
  $update_rp = str_replace(array('<1>', '<2>'), array(join(', ', $updlist), $p_id), $Update_Query);
  echo $update_rp;
tell me how that does the job ;)

Posted: Tue Nov 08, 2005 10:01 am
by vincenzobar
kind of worked

Code: Select all

if(isset($results_rp) && isset($num_rows_rp)){

//store XML IDs in an array... 
$XML_IDList = explode(',', $temp[21]); 
print_r( $XML_IDList);

//fetch all the DB IDs in an array to reduce tons of DB query...  
$idrs = mysql_query("SELECT productid FROM CB_rateplan") or die(mysql_error()); 



while($row = mysql_fetch_row($idrs)) 
$DB_IDList[] = $row[0]; 
$Update_Query = "UPDATE CB_rateplan SET <1> WHERE productid=<2>";

//match and update/add as needed... trifle now  
foreach($XML_IDList as $p_id) 
{ 
	if(in_array($p_id, $DB_IDList)) 
{ 
  foreach($column as $i=>$col) {
   if($i != 21){ //avoid id field  
   $updlist[] = "$col='$temp[$i]'"; 
  $update_rp = str_replace(array('<1>', '<2>'), array(join(', ', $updlist), $p_id), $Update_Query); 
  echo $update_rp;
  }
  }
	
	}else {
 	$add_rp = "INSERT INTO CB_rateplan $rows VALUES $values ;"; 
  	echo $add_rp;
  	//mysql_query($add_rp);
  	} 
}
}

}else{

//standard insert if table is empty - this works!
}
It seems to do alot of repetition though and only checks for one value of Array id and updates the same thing for every occurance... i think

take a look i will stop playing with the page till you respond so you can see the exact output i do

http://www.underwaterdesign.com/xml/output-rate.php

Posted: Tue Nov 08, 2005 10:06 am
by vincenzobar
actually what it is doing is slowly adding a value per occurance for only the one id which is the last ID in the XML Array

so what i need is the last outputed value per matching ID

so you know every id is a match currently and there areabout 130 of them

Posted: Tue Nov 08, 2005 10:25 am
by vincenzobar
ok fixed loop by moving out the echo statement from the foreach loop now i get one value which is what i need but still it is only one there should be like 130 of them the XML_IDList is the problem

Posted: Tue Nov 08, 2005 2:00 pm
by vincenzobar
ALMOST THERE!!!!

I added $XML_IDList[] = $temp[21]; into my parsing loop to get the values for the $XML_IDList to become more then just the last number in the array. it now contains all numbers in the sheet.

Now this almost works

Code: Select all

while($row = mysql_fetch_row($idrs)) 
$DB_IDList[] = $row[0]; 
$Update_Query = "UPDATE CB_rateplan SET <1> WHERE productid=<2>";

//match and update/add as needed... trifle now  
foreach($XML_IDList as $p_id) { 
	print "p_id; ".$p_id. "<BR>";

	if(in_array($p_id, $DB_IDList)) { 
	
  		foreach($column as $i=>$col) {
   			if($i != 21){ //avoid id field  
   				$updlist[] = "$col='$temp[$i]'"; 
   			}//if 3
  		}//foreach 2
  
  	$update_rp = str_replace(array('<1>', '<2>'), array(join(', ', $updlist), $p_id), $Update_Query);
	echo $update_rp. "<BR><BR>";
	
	}else { //if 2
 		$add_rp = "INSERT INTO CB_rateplan $rows VALUES $values ;"; 
  		echo $add_rp;
  	//mysql_query($add_rp);
  	} //if 2continued
}//foreach one
now the problem is that with every Prod_id the Update statement just dublicates with the same value
p_id; 53037
UPDATE CB_rateplan SET planname='America\'s Choice with Push to Talk Family Share 6000 (Includes 2 Lines)', planminutes='6000', monthlyaccessfee='319.9900', additionalairtimefee='0.2000', activationfee='20.0000', roamfee='0', roamingfee='$0.00/min - no roaming charges', contractmonth='24', cancellationfee='$175.00', peakrate='', offpeakrate='', includedairtimeoffpeak='50000', includedairtimepeak='', nightweekendminutes='unlimited night & weekend minutes', extraminutes='', longdistancerate='0', longdistanceratestring='$0.00 (included)', nationalplanind='', peakhours='', offpeakhours='9:01pm - 5:59am monday - friday; 2:00am saturday - 11:59pm sunday', offpeakdays='', productid='54278', carrierdescription='verizon wireless', imagefilelocation='images/carriers/', imagefilename='verizonlogo.gif', sharedplan='true', rateplanid='14377' WHERE productid=53037

p_id; 53103
UPDATE CB_rateplan SET planname='America\'s Choice with Push to Talk Family Share 6000 (Includes 2 Lines)', planminutes='6000', monthlyaccessfee='319.9900', additionalairtimefee='0.2000', activationfee='20.0000', roamfee='0', roamingfee='$0.00/min - no roaming charges', contractmonth='24', cancellationfee='$175.00', peakrate='', offpeakrate='', includedairtimeoffpeak='50000', includedairtimepeak='', nightweekendminutes='unlimited night & weekend minutes', extraminutes='', longdistancerate='0', longdistanceratestring='$0.00 (included)', nationalplanind='', peakhours='', offpeakhours='9:01pm - 5:59am monday - friday; 2:00am saturday - 11:59pm sunday', offpeakdays='', productid='54278', carrierdescription='verizon wireless', imagefilelocation='images/carriers/', imagefilename='verizonlogo.gif', sharedplan='true', rateplanid='14377', planname='America\'s Choice with Push to Talk Family Share 6000 (Includes 2 Lines)', planminutes='6000', monthlyaccessfee='319.9900', additionalairtimefee='0.2000', activationfee='20.0000', roamfee='0', roamingfee='$0.00/min - no roaming charges', contractmonth='24', cancellationfee='$175.00', peakrate='', offpeakrate='', includedairtimeoffpeak='50000', includedairtimepeak='', nightweekendminutes='unlimited night & weekend minutes', extraminutes='', longdistancerate='0', longdistanceratestring='$0.00 (included)', nationalplanind='', peakhours='', offpeakhours='9:01pm - 5:59am monday - friday; 2:00am saturday - 11:59pm sunday', offpeakdays='', productid='54278', carrierdescription='verizon wireless', imagefilelocation='images/carriers/', imagefilename='verizonlogo.gif', sharedplan='true', rateplanid='14377' WHERE productid=53103
And bigger and bigger and bigger

What needs to happen been trying stuff for hours with no success. All i can see is that productid in the value array is only equating to the last in the array again and not matching to the call.



AAARGGGGGGGGG![/b]

Posted: Wed Nov 09, 2005 2:59 am
by n00b Saibot
add $updlist = array(); before the 2nd foreach loop :wink:

Posted: Wed Nov 09, 2005 7:51 am
by vincenzobar
Kool... it no longer grows in size but it only updates the same info for every ID instead of the corresponding update from the array!

I think i am going to try another route with an archive database. I have spent to much time on this

I think i am going to grab all rows with the same P-id and move them to an archive Table then delete them and then insert the new data. Now they want a history of changes that aren't in the production table and this could be a hella lot easier!!!

If you have any helpful tips that could make this work eaiser then please by all means let me know!!! I have spent a week on this and I have till friday to finish it!

Time to archive!!!!

Thanks for your help you taught me alot!