Jump to content

blinks

Members
  • Posts

    53
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

blinks's Achievements

Member

Member (2/5)

0

Reputation

  1. Did it; set second $fieldNodeList to $fieldNodeList->item(0)->setAttribute('type', 'test'); :-)
  2. I have a series of xml files, which contain the line: <para type="series"> which I want to change to <para type="test"> I'm using the following code for an individual file, but the change is not happening. Any advice appreciated. $doc = DOMDocument::loadXML($xmlString); $xpath = new DOMXPath($doc); $fieldNodeList = $xpath->query("/para"); $fieldNodeList->setAttribute('type', 'test'); $newXML = $doc->SaveXML();
  3. Smoseley, thanks so much. That did the trick! And thanks, Pikachu2000 for that reformatting :-)
  4. Smoseley, thanks for your reply. Unfortunately array_merge doesn't do what I want, as it simply appends one array after the other. Apologies for my arrays being so badly formatted and hard to read. What I want to do is merge the arrays so that keys/values that exist in both arrays are retained; and where a key exists in both arrays, also retain all values in both arrays.
  5. I have 2 arrays: Array1= ([0] => Array ( [id] => 521 [countA] => 2 [dateA] => 2011-11-07 ) [1] => Array ( [id] => 647 [countA] => 5 [dateA] => 2011-12-07 ) [2] => Array ( [id] => 660 [countA] => 1 [dateA] => 2011-11-03 )) Array2= ( [0] => Array ( [id] => 321 [countB] => 2 [dateB] => 2011-12-07 ) [1] => Array ( [id] => 645 [countB] => 5 [dateB] => 2011-11-01 ) [2] => Array ( [id] => 660 [countB] => 1 [dateB] => 2011-12-07 )) which I want to combine into a single array: Result= ( [0] => Array ( [id] => 321 [countA] => [dateA] => [countB] => 2 [dateB] => 2011-12-07 ) [1] => Array ( [id] => 521 [countA] => 2 [dateA] => 2011-11-07 [countB] => [dateB] => ) [2] => Array ( [id] => 645 [countA] => [dateA] => [countB] => 5 [dateB] => 2011-11-01 ) [3] => Array ( [id] => 647 [countA] => 5 [dateA] => 2011-12-07 [countB] => [dateB] => ) [4] => Array ( [id] => 660 [countA] => 1 [dateA] => 2011-11-03 [countB] => 1 [dateB] => 2011-12-07 )) Is it possible to do this via something like array_diff, without having to loop through the arrays?
  6. Thanks sunfighter, have applied your suggestions, and everything works!! Thank you so much, I have been struggling with this code for almost 2 weeks.
  7. The first WHILE loop in the code below is executing correctly on the first go-round, and successfully updating the trade_offers table at the end of the loop. In the 2nd go round, it should use the updated values from trade_offers, but instead is using the original values. Would appreciate any help in locating the problem. There are no errors being output. $getdeclined="SELECT * FROM trade_offers WHERE pokemon_trade_id=$id"; $declined=mysql_query($getdeclined); while($row = mysql_fetch_array($declined)){ $getpostrade="SELECT * FROM trade_offers WHERE pokemon_trainer = '$row[pokemon_trainer]'"; $postrade=mysql_query($getpostrade) or die(mysql_error());; while ($row2 = mysql_fetch_array($postrade)){ $tradepos = $row2['pokemon_pos'];} if ($tradepos==NULL){ $tradepos=0;} $getpostrainer="SELECT * FROM pokemon_trainer WHERE pokemon_trainer = '$row[pokemon_trainer]'"; $postrainer=mysql_query($getpostrainer) or die(mysql_error());; while ($row3 = mysql_fetch_array($postrainer)){ $trainerpos = $row3['pokemon_pos'];} if ($tradepos>$trainerpos){ $newpos = $tradepos;} else if ($trainerpos>$tradepos){ $newpos = $trainerpos;} $newpos +=1; $update="UPDATE trade_offers SET pokemon_pos = $newpos WHERE pokemon_id = $row[pokemon_id]"; $result=mysql_query($update) or die(mysql_error());; $newpos = 0; }
  8. Thanks spiderwell and maq. The error displaying is _ Notice: Undefined index: x in /home/pokemond/public_html/trade.php on line 170
  9. When I run the MySQL queries in the code below in SQLyog, the $pokemon_pos in the "SELECT max(pokemon_pos)" part of the statement is always correct (i.e. alias "x" is correct). Yet when wrapped up in PHP, $newpos, which relies on "x" is always undefined. I'd greatly appreciate any help in troubleshooting this code - $getdeclined="SELECT * FROM trade_offers WHERE pokemon_trade_id=$_GET[id]"; $declined=mysql_query($getdeclined); while ($row = mysql_fetch_array($declined)){ $getdecusername="SELECT MAX(pokemon_pos) FROM ( SELECT pokemon_pos FROM pokemon_trainer WHERE pokemon_trainer = '$row[pokemon_trainer]' UNION SELECT pokemon_pos FROM trade_offers WHERE pokemon_trainer = '$row[pokemon_trainer]' AND pokemon_trade_id = $_GET[id] ) AS x"; $decusername=mysql_query($getdecusername); while($row2 = mysql_fetch_array($decusername)){ $newpos = $row2['x'];} echo $newpos; $newpos +=1; } }
  10. Thanks Keith; that works beautifully when I run the SQL alone. Packaged up with some PHP, it is coming back as undefined, so I guess the problem must be with my PHP. Thanks heaps for your help!
  11. Sorry, I should have said - I'd appreciate help with creating an SQL query to retrieve the highest value for Bob, whether it be in Table 1 or Table 2. The queries I create keep coming back as "undefined". TIA
  12. As the title says I want to retrieve the highest value from 2 tables where C1 = 'Bob'. Based on the mock-up tables below it should grab 50 from Table 2. Table 1 C1C2 Bob48 Will62 Table 2 C1C2 Bob50 Will59
  13. I'd appreciate any assistance with the following code. When I echo the output, all the variables are correct, except that pokemon_pos is always 1, whereas it should be something like 49, which is the highest value in either tables trade_offers or pokemon_trainer for a given pokemon_trade_id. $getdeclined="SELECT * FROM trade_offers WHERE pokemon_trade_id=$_GET[id]"; $declined=mysql_query($getdeclined); while ($row = mysql_fetch_array($declined)){ $getdecusername="select max(pokemon_pos) from ( select max(pokemon_pos) as pokemon_pos from pokemon_trainer WHERE pokemon_trainer = '$row[pokemon_trainer]' union all select max(pokemon_pos) from trade_offers WHERE pokemon_trainer = '$row[pokemon_trainer]' AND pokemon_trade_id = $_GET[id] ) as x"; $decusername=mysql_query($getdecusername); while ($row2 = mysql_fetch_array($decusername)){ $newpos = $row2['pokemon_pos']; $newpos +=1; } $update="UPDATE trade_offers SET pokemon_pos = $newpos WHERE pokemon_id = $row[pokemon_id]"; $result=mysql_query($update); }
  14. The following code won't work - $insert = "INSERT INTO temp_wild * SELECT * FROM pokemon_data WHERE pokemon_name = '$pkfind'" $result = mysql_query($insert) or die(mysql_error()); although it will if I replace the first '*' with all the individual column names. But there are a lot of columns, and I don't want to specify them all. Is it possible to use '*' or something else to signfiy "all" in the above query? TIA
  15. I am having trouble displaying values in the multidimensional array at the bottom of this script. I can display the value of an element by specifying the sub-arrays e.g. echo $parsedxml['oaklistinfo']['contact']['contactname']; But surely there must be a way to specify an element without listing each of the sub-array names? Here's my code - <?php //Copyright Daniel FAIVRE 2005 - www.geomaticien.com function simplexml2array($xml) { if (get_class($xml) == 'SimpleXMLElement') { $attributes = $xml->attributes(); foreach($attributes as $k=>$v) { if ($v) $a[$k] = (string) $v; } $x = $xml; $xml = get_object_vars($xml); } if (is_array($xml)) { if (count($xml) == 0) return (string) $x; // for CDATA foreach($xml as $key=>$value) { $r[$key] = simplexml2array($value); } if (isset($a)) $r['@'] = $a; // Attributes return $r; } return (string) $xml; } $issn = $_GET['issn']; $baseurl = "http://www.oaklist.qut.edu.au/api/basic?query=".$issn; $xml = simplexml_load_file($baseurl); $parsedxml = simplexml2array($xml); print_r($parsedxml); echo "<br />"; //$i = 0; //for ($i = 0; i<count($parsedxml[$i]); $i++) { echo $parsedxml['oaklistinfo']['contact']['contactname']; echo "<br />"; echo $parsedxml['record']['copyright']['copyrightstatement']; // } ?>
×
×
  • 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.