Jump to content

blinks

Members
  • Posts

    53
  • Joined

  • Last visited

    Never

Everything posted by blinks

  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']; // } ?>
  16. blinks

    JSON

    Okay, figured it out ... the server I'm using is on PHP 5.1.6; and JSON code doesn't come in until 5.2. Thanks all for your help!
  17. blinks

    JSON

    Sorry, pasting again without the code tags (thought that would help with spacing, but it didn't) - ?({ "OCLC:32177181": { "bib_key": "OCLC:32177181", "preview": "full", "thumbnail_url": "http://covers.openlibrary.org/b/id/4586826-S.jpg", "preview_url": "http://openlibrary.org/details/oversighthearing081194unit", "info_url": "http://openlibrary.org/books/OL894002M" } });
  18. blinks

    JSON

    Here's what I get with an echo straight after the utf8_encode statement - ?({ "OCLC:32177181": { "bib_key": "OCLC:32177181", "preview": "full", "thumbnail_url": "http://covers.openlibrary.org/b/id/4586826-S.jpg", "preview_url": "http://openlibrary.org/details/oversighthearing081194unit", "info_url": "http://openlibrary.org/books/OL894002M" } });
  19. blinks

    JSON

    No, this is the whole thing; have just replaced the last line with something else, but still no joy - <?php $url= "http://openlibrary.org/api/books?bibkeys=OCLC:32177181&callback=?"; $contents = file_get_contents($url); $contents = utf8_encode($contents); $results = json_decode($contents); print $results->{'preview'}; ?>
  20. blinks

    JSON

    That's weird, as I'm not getting anything at all, with either IE or FF.
  21. blinks

    JSON

    The following bit of code is throwing back no results, and I can't figure out why. The problem is with the json_decode line - $url= "http://openlibrary.org/api/books?bibkeys=OCLC:32177181&callback=?"; $contents = file_get_contents($url); $contents = utf8_encode($contents); $results = json_decode($contents); var_dump($results); TIA
  22. I have a long and complicated SQL query, which I've cut back to it's bare bones here - SELECT frsk.pid AS PID, frsk.title AS TITLE, group_concat(DISTINCT frsk_ismemberof.ismemberof ORDER BY frsk_ismemberof.ismemberof DESC SEPARATOR '|') AS COLLECTION FROM frsk LEFT JOIN frsk_ismemberof ON pid=ismemberof_pid WHERE date BETWEEN '2003-01-01 00:00:00' AND '2008-12-31 23:59:59' GROUP BY pid the query works as intended, above. However, the group_concat line is a collection of ID #s which I want to replace with ID names, using the following subquery - select DISTINCT(frsk.title) from frsk, frsk_ismemberof where frsk.pid=frsk_ismemberof.ismemberof However, I can't figure out how to incorporate the subquery into the group_concat line; I keep getting a "subquery has more than one line" message. TIA
  23. Thanks! Changing $diff to $discrepancy and removing that 2nd $i++ did the trick :-) Oh, and the brackets around the "if"
  24. The "for" part of the following code is not working; can anyone help me understand why? $stmt = "SELECT id FROM table"; $result = mysql_query($stmt) or die (mysql_error()); while ($row = mysql_fetch_assoc($result)) { $all_pids[] = $row['id']; } for ($i=0;$i<count($diff);$i++) { if in_array($discrepancy[$i]['id'], $all_pids) { unset($discrepancy[$i]); } else { } i++; } TIA
  25. Gosh, that was it! Thank you! <banging my forehead!>
×
×
  • 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.