PHP - Count Child Nodes In Phpsimpledom
Hi guys, I'm using PHP Simple DOM, thanks to the good folk her I'm making progress. The html i'm parsing has a bunch of links in a li ul structure. I've managed to get the top layer of links extracted and I would like to have a count of the number of child nodes in the layer below the main links. Here is my code: $html = file_get_html('test/php/book.html'); if(!empty($html)){ $lis = $html->find('.chunklist', 0)->children() ; for ( $i = 0 ; $i < count($lis) ; $i++ ) { $parent_term = $lis[$i]->first_child()->innertext . ', ' ; $parent_node = $lis[$i]->children[0]->attr['href'] . '<br>' ; //echo count($parent_node->children()) ; this gives error Warning: count(): Parameter must be an array or an object that implements Countable echo $parent_term . $parent_node ; $parent_node = $const . $parent_node ; echo $parent_node ; $html2 = file_get_html($parent_node) ; $lis2 = $html2->find('.chunklist', 0)->children() ; } } I don't see anything in the manual regarding counting nodes, any idea how to go about this? Similar Tutorialsgood day dear phpfreaks.
I am new to PHP's SimpleXML. i want to work with SimpleXML on OSM-files. The original version of this question was derived from he OSM Data parsing to get the nodes with child https://stackoverflow.com/questions/16129184/osm-data-parsing-to-get-the-nodes-with-child
I am thankful that hakre offered a great example in the comments that makes a overwhelming goal: how to get more out of it: I want to filter the data to get the nodes with special category. Here is sample of the OSM data I want to get the whole schools within an area. The first script runs well - but now I want to refine the search and add more tags. Finally I want to store all into MySQL. So we need to make some XML parsing with PHP:
The following is a little OSM Overp
Quote
since i am learning - i break down the code into pieces...For my question, the second part is more interesting here. That is querying the XML data we have already. Again - as mentioned above: This is most easily done with xpath, the used PHP XML library is based on libxml which supports XPath 1.0 which covers the various querying needs very well. The following example lists all schools and tries to obtain their names as well.
# get all school nodes with xpath //node[tag[@k = "amenity" and @v = "school"]] This line says: Give me all node elements that have a tag element inside which has the k attribute value "amenity" and the v attribute value "school". Explanation: This is the condition we have to filter out those nodes that are tagged with amenity school. Further on xpath is used again - a second time: now relative to those school nodes to see if there is a name and if so to fetch it: Therefore we use the foreach-syntax:
foreach ($schools as $index => $school)
tag[@k = "name"]/@v'
tag[@k = "name"]/@v' Because not all school nodes have a name, a default string is provided for display purposes by adding it to the (then empty) result array:
list($name) = $school->xpath('tag[@k = "name"]/@v') + ['(unnamed)'];
Query returned 907 node(s) and took 1.10735 seconds. goal: to get out even more important data - see here Key:contact - OpenStreetMap Wiki
Well - we are already extracting the name: If we want to have more data then we just have to run a few more xpath queries inside our loop for all the address keys and the website. So - additionally: we do not have to forget to look for the website key additional to contact:website. cf: https://wiki.openstreetmap.org/wiki/Key:website conclusio: well - i think that i need to extend the xpath requests within the loop where xpath is used again, now relative to those school nodes to see if there is a name and if so to fetch it:
tag[@k = "name"]/@v' i did some further tess and found out very interesting things
$query = 'node
$context = stream_context_create(['http' => [
# please do not stress this service, this example is for demonstration purposes only.
$result = simplexml_load_file($endpoint);
//
# get all school nodes with xpath
$query = 'node
$context = stream_context_create(['http' => [
$endpoint = 'http://overpass-api.de/api/interpreter';
$result = simplexml_load_file($endpoint);
me/martin/dev/php/o1.php on line 68
33 School(s) found:
so far so good : if i add some lines in the part 2 i run into errors... -see below: i want to get more data out of it: - and coded like so;
{ note - within the part 2 that works with the XML-Result.
//
# get all school nodes with xpath
contact:phone I will dig into all documents and come back later the weekend... and report all the findings well - i think that i need to extend the xpath requests within the loop where xpath is used again, now relative to those school nodes to see if there is a name and if so to fetch it:
tag[@k = "name"]/@v'
more infos So here's what I'm trying to do, and I haven't found any clear tutorials on how to properly navigate a DOMDocument object, at least not in the strict sense of PHP. I'm building a web scraper, I've had it working for some time now using more traditional methods (a combination of string manipulation and clever regex). I've been told xpath can be much faster and more reliable for what I need. Sold. Let's say I'm parsing a forum. This forum separates each reply in a post with a set of <li></li> with a class of "message" Code: [Select] <li class="message"> // Stuff here </li> <li class="message"> // Stuff here </li> So far so good. These list items contain all the formatting for each post, including user info and the message text. Each sitting in it's own div. Code: [Select] <li class="message"> <div class="user info"> User info here </div> <div class="message text"> Message text here </div> </li> <li class="message"> <div class="user info"> User info here </div> <div class="message text"> Message text here </div> </li> Still with me? Good. With this bit of code I can select each message list item block and iterate over all the sub nodes inside. Code: [Select] $items = $xpath->query("//li[starts-with(@class, 'message')]"); for ($i = 0; $i < $items->length; $i++) { echo $items->item($i)->nodeValue . "\n"; } This produces a basic text dump of the entire forum. Close, but not what I need. What I'm trying to do is as follows Select all the class="message" list items [done] Once those have been selected, run another $xpath->query to select the child nodes which contain the user info and message text Step one is done, step two is what is confusing me. How can I run a new query based on the output from the first query? Thanks guys Hi I'm trying to count XML elements and generate table row and cell as per result. XML entries generated by users what I'm trying to do is auto generate table rows and cols and paging them bec if XML file get heavier its hard to get results it slow down processing that's why i appreciate paging My XML: Code: [Select] <note> <a1>Keep holding On - Avril Lavigne </a1> <a2>Miley Cyrus - Party In The U.S.A </a2> <a3>Swift Taylor - Breath </a3> <a4>Coldplay - The Hardest Part </a4> <a5>P!nk - Who Knew </a5> <a6>Eminem - Love The Way You Lie ft. Rihanna </a6> <a7>Nelly Furtado - Say It Right </a7> <a8>The Black Eyed Peas - Meet Me Halfway </a8> <a9>Justin Bieber - Baby ft. Ludacris </a9> <a10>N.E.R.D. - Hot-n-Fun (Official Version) ft. Nelly Furtado </a10> </note> Hi I am trying to create a hierarchy array from our mysql database. What i have so far is: //instantiate DB & connect $database = new Database(); $db = $database->connect(); //instantiate question object $question = new Question($db); //query $results = $question->read(); //check for data if ($results) { $question_arr['questions'] = array(); $child_arr = array(); while ($row = $results->fetch(PDO::FETCH_ASSOC)) { array_push($question_arr['questions'], $row); $question_arr['questions'][] = buildTree($row); } print_r($question_arr['questions']); } else { echo json_encode(array('message'=>'nothing here!.')); } function buildTree($child) { $branch = array(); foreach ($child as $row) { $childresults = $question->read_children($row['parentid']); while ($childrow =$childresults->fetch(PDO::FETCH_ASSOC)) { $children = buildTree($childrow); if ($children) { $row['children'] = $children; } $branch[] = $childrow; } } //} return $branch; } in my Questions.php file: <?php class Question{ private $conn; public $id; public $childid; public $parentid; public $question; public $pageid; public $numclicks; public $typeid; public $date_created; // Constructor with DB public function __construct($db) { $this->conn = $db; } public function read() { //create query(sql statement) $query = 'SELECT id as parentid, question, pageid, typeid,numclicks,date_created from ct_questions'; // Prepare statement $stmt =$this->conn->prepare($query); // Execute query $stmt->execute(); return $stmt; } public function read_children($parentid) { //This is from a View I created in Mysql $query = 'SELECT parent_question, parentid, parent_pageid, child_question, childid, child_pageid from ct_vquestion_parent_child_lookup where parentid='.$parentid.''; // Prepare statement $stmt = $this->conn->prepare($query); // Execute query $stmt->execute(); return $stmt; } }
the current errors i am getting a <br /> <b>Notice</b>: Undefined variable: question in <b>C:\htdocs\api\questions\read.php</b> on line <b>41</b><br /> <br /> <b>Fatal error</b>: Uncaught Error: Call to a member function read_children() on null in C:\htdocs\api\questions\read.php:41 Stack trace: #0 C:\htdocs\api\questions\read.php(28): buildTree(Array) #1 {main} thrown in <b>C:\htdocs\api\questions\read.php</b> on line <b>41</b><br /> Hi guys, I need your help. I am trying to insert the rows in the mysql database as I input the values in the url bar which it would be like this: Code: [Select] www.mysite.com/testupdate.php?user=tester&pass=test&user1=tester&email=me@shitmail.com&ip=myisp However i have got a error which i don't know how to fix it. Error: Column count doesn't match value count at row 1 <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $adduser = clean($_GET['user1']); $email = clean($_GET['email']); $IP = clean($_GET['ip']); if($username == '') { $errmsg_arr[] = 'username is missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD is missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $sql = "INSERT INTO `members` (`username`,`email`,`IP`) VALUES ('$adduser','$email','$IP')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated."; } ?> Here's the name of the columns i have got in my database: Code: [Select] username IP I have input the correct columns names, so I can't correct the problem I am getting. Please can you help? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331562.0 Hi all, i have a very large xml file containing 2000 child nodes. i am using DOMDocument to read xml data but it shows whole data at once, i want to fetch first 20 or 30 nodes first time and then rest leave for pagination. is there any way to do so. to read only first few records from xml file. Thanks in advance... Hello... I want to draw a nodes with arcs by using PHP. Is there any package available to do this? My nodes values are gene name. Please help me......... Using HTML5 and CSS3, and jQuery is available.
I have a form block enclosing several hidden div blocks. jQuery will unhide a div block on selecting a control node -- presented as a tab.
I need to have a form input appear in more than one div block. That is, the HTML has four tabs, each tab making visible one of four div blocks. On one of the four div blocks, a specific form input is present.
I need for this specific input to also appear in one of the other div blocks. I want the one input, coded in one of the div blocks, to be "seen" and be operational in another div block -- but not have the HTML code for it located or duplicated there.
I thought about adding another input tag with the same name and showing the same value, but that is unworkable as it stands. I do not want to replicate or duplicate or otherwise make two separate inputs. But...
My current plan is to have two inputs of the same name, but the input in the hidden div block is disabled. By being disabled, the value of it will not be submitted. When the second div block becomes visible, the first input is disabled and the second is enabled. I would also need to copy the newly entered value into the other same-named input.
Could there be a better way?
Another way would be to move the specific input outside of the div blocks so that it is always visible. But I do not care to have this input visible for all the div blocks when each becomes visible.
Edited by bsmither, 08 January 2015 - 12:21 AM. Hi I have searched around for a solution to this and either fail to grasp how to get it to work or just cannot find the correct solution. I have the following XML file: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <root> <product> <id>153</id> <images> <image id="1"> <url>http://www.mysite.com/product/images/1322.jpg</url> <title> <en>Book 1</en> </title> </image> <image id="2"> <url>http://www.mysite.com/product/images/1321.jpg</url> <title> <en>Book 2</en> </title> </image> <image id="3"> <url>http://www.mysite.com/product/images/1316.jpg</url> <title> <en>Book 3</en> </title> </images> </product> <product> <id>154</id> <images> <image id="1"> <url>http://www.mysite.com/product/images/1322.jpg</url> <title> <en>Book 1</en> </title> </image> <image id="2"> <url>http://www.mysite.com/product/images/1321.jpg</url> <title> <en>Book 2</en> </title> </image> <image id="3"> <url>http://www.mysite.com/product/images/1316.jpg</url> <title> <en>Book 3</en> </title> </images> </product> </root> $xml = 'example.xml'; // URL for feed. try{ $feed = new SimpleXMLElement($xml, null, true); }catch(Exception $e){ echo $e->getMessage(); exit; } $sql = 'INSERT INTO images (`id`, `url`) VALUES '; foreach($feed->property as $property){ $sql .= sprintf( "\n('%d', '%s'),", $property->id, mysql_real_escape_string($property->images->image->url) ); } $sql = rtrim($sql, ',') . ';'; What I need to do is loop through each of the image url nodes and insert them into my DB with the relevant id. Can somebody point me in the right direction with this please its driving me nuts! Regards GT Why am I getting this error when there are 3 Fields with 3 values? Column count doesn't match value count at row 1 Code: [Select] $sql5="INSERT INTO participants (participant_name, team_no, sport) VALUES ('".implode("','$_POST[team]'),('",$_POST['participant_name'])."','$_POST[team]','$sport')"; Hi! I'm having trouble accessing data with simpleXML_load_file I have a working script that loads an XML-file and outputs in a proprietary format that I've written, but for some reason I can't get it to work with this second set of XML-files. Loading the file seems to work fine. I load the file into a variable, and can print the contents of the file using echo $xml -> asXML(); However, when I try to access a single node using: echo $xml->{'SOAP-ENV:Envelope'}->{'SOAP-ENV:Body'}->Order->OrderHeader->OrderNumber->BuyerOrderNumber;I get the following error: Notice: Trying to get property of non-object in C:\www\convert_uio.php on line 28 XML-file looks as follows: <?xml version="1.0" encoding="utf-8"?> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Header> <nseps:endpoints SOAP-ENV:mustUnderstand="true" xmlns:nseps="urn:schemas-IBX:/docs/endpoint.nsendpoint"> <nseps:to> <nseps:address>8b51fc8c-7aba-1000-bbbe-c0a878330001</nseps:address> </nseps:to> <nseps:from> <nseps:address>1b0ad9d6-7a05-1000-a43c-c0a878330001</nseps:address> </nseps:from> </nseps:endpoints> <nsprop:properties SOAP-ENV:mustUnderstand="true" xmlns:nsprop="urn:schemas-IBX:/docs/property.nsproperty"> <nsprop:identity>fb1797dbb1f14a179482b1bb53bc7c14</nsprop:identity> <nsprop:sentAt>2014-09-02T00:00:00+01:00</nsprop:sentAt> <nsprop:topic>Order</nsprop:topic> </nsprop:properties> </SOAP-ENV:Header> <SOAP-ENV:Body> <Order xmlns="rrn:org.xcbl:schemas/xcbl/v3_5/xcbl35.xsd"> <OrderHeader> <OrderNumber> <BuyerOrderNumber>E14124673</BuyerOrderNumber> </OrderNumber> <OrderIssueDate>20140902T00:00:00+01:00</OrderIssueDate> <OrderReferences> <AccountCode> <Reference> <RefNum>no_unoslo</RefNum> </Reference> </AccountCode> </OrderReferences> <Purpose> <PurposeCoded>Original</PurposeCoded> </Purpose> <RequestedResponse> <RequestedResponseCoded>NoAcknowledgementNeeded</RequestedResponseCoded> </RequestedResponse> <OrderType> <OrderTypeCoded>PurchaseOrder</OrderTypeCoded> </OrderType> <OrderCurrency> <Currency> <CurrencyCoded>NOK</CurrencyCoded> </Currency> </OrderCurrency> <OrderLanguage> <Language LanguageDependent="false"> <LanguageCoded>no</LanguageCoded> </Language> </OrderLanguage> <OrderDates> <RequestedDeliverByDate>20140904T00:00:00+01:00</RequestedDeliverByDate> </OrderDates> <OrderParty> <BuyerParty> <Party> <PartyID> <Identifier> <Agency> <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded> </Agency> <Ident>no_uio</Ident> </Identifier> </PartyID> <NameAddress> <Name1>xxxxxxxxxxxxx</Name1> <Name2>xxxxxxxxxxxxx</Name2> <POBox>xxxxx</POBox> <PostalCode>NO-0316</PostalCode> <City>Oslo</City> <Country> <CountryCoded>NO</CountryCoded> </Country> </NameAddress> <OrderContact> <Contact> <ContactName>Some Name</ContactName> <ContactFunction> <ContactFunctionCoded>PurchasingContact</ContactFunctionCoded> </ContactFunction> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>email@email.no</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>+4700000000</ContactNumberValue> <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </OrderContact> </Party> </BuyerParty> <BuyerTaxInformation> <PartyTaxInformation> <TaxIdentifier> <Identifier> <Agency> <AgencyCoded>Other</AgencyCoded> <AgencyCodedOther>VAT Number</AgencyCodedOther> </Agency> <Ident>00000000</Ident> </Identifier> </TaxIdentifier> </PartyTaxInformation> </BuyerTaxInformation> <SellerParty> <Party> <PartyID> <Identifier> <Agency> <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded> </Agency> <Ident>8b51fc8c-7aba-1000-bbbe-c0a878330001</Ident> </Identifier> </PartyID> <NameAddress> <Name1>Name 2</Name1> <Street>Adress</Street> <PostalCode> 0314</PostalCode> <City>OSLO</City> <Country> <CountryCoded>NO</CountryCoded> </Country> </NameAddress> <OrderContact> <Contact> <ContactName>N/A</ContactName> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>email</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>47 0000000</ContactNumberValue> <ContactNumberTypeCoded>FaxNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </OrderContact> </Party> </SellerParty> <ShipToParty> <Party> <PartyID> <Identifier> <Agency> <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded> </Agency> <Ident /> </Identifier> </PartyID> <NameAddress> <Name1>Name</Name1> <Name2>Name2 </Name2> <Street>Adress</Street> <StreetSupplement1>0318 Oslo</StreetSupplement1> <PostalCode>NO-0562</PostalCode> <City>OSLO</City> <Country> <CountryCoded>NO</CountryCoded> </Country> </NameAddress> <OrderContact> <Contact> <ContactName>Name</ContactName> <ContactFunction> <ContactFunctionCoded>PurchasingContact</ContactFunctionCoded> </ContactFunction> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>emamil</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>+470000000</ContactNumberValue> <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </OrderContact> <ReceivingContact> <Contact> <ContactName>Name</ContactName> <ContactFunction> <ContactFunctionCoded>PurchasingContact</ContactFunctionCoded> </ContactFunction> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>email</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>+4700000000</ContactNumberValue> <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </ReceivingContact> </Party> </ShipToParty> <BillToParty> <Party> <PartyID> <Identifier> <Agency> <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded> </Agency> <Ident>no_uio</Ident> </Identifier> </PartyID> <NameAddress> <Name1>Name</Name1> <Name2>Adress</Name2> <POBox>adress2</POBox> <PostalCode>NO-0316</PostalCode> <City>Oslo</City> <County /> <District>9908:971035854</District> <Country> <CountryCoded>NO</CountryCoded> </Country> </NameAddress> <OrderContact> <Contact> <ContactName>Name</ContactName> <ContactFunction> <ContactFunctionCoded>PurchasingContact</ContactFunctionCoded> </ContactFunction> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>email</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>+470000000</ContactNumberValue> <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </OrderContact> </Party> </BillToParty> </OrderParty> <OrderTermsOfDelivery> <TermsOfDelivery> <TermsOfDeliveryFunctionCoded>Other</TermsOfDeliveryFunctionCoded> <TermsOfDeliveryFunctionCodedOther>Other</TermsOfDeliveryFunctionCodedOther> <TransportTermsCoded>Other</TransportTermsCoded> <TransportTermsCodedOther>DDP</TransportTermsCodedOther> <ShipmentMethodOfPaymentCoded>Other</ShipmentMethodOfPaymentCoded> <ShipmentMethodOfPaymentCodedOther>Other</ShipmentMethodOfPaymentCodedOther> <TransportDescription /> </TermsOfDelivery> </OrderTermsOfDelivery> <OrderHeaderNote /> </OrderHeader> <OrderDetail> <ListOfItemDetail> <ItemDetail> <BaseItemDetail> <LineItemNum> <BuyerLineItemNum>1</BuyerLineItemNum> </LineItemNum> <LineItemType> <LineItemTypeCoded>Item</LineItemTypeCoded> </LineItemType> <ItemIdentifiers> <PartNumbers> <SellerPartNumber> <PartNum> <PartID>1000000000001</PartID> </PartNum> </SellerPartNumber> <ManufacturerPartNumber> <PartID /> </ManufacturerPartNumber> </PartNumbers> <ItemDescription>Normal frakt, pris 20 NOK</ItemDescription> </ItemIdentifiers> <TotalQuantity> <Quantity> <QuantityValue>1</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> </TotalQuantity> <OffCatalogFlag>false</OffCatalogFlag> </BaseItemDetail> <PricingDetail> <ListOfPrice> <Price> <UnitPrice> <UnitPriceValue>20</UnitPriceValue> <Currency> <CurrencyCoded>NOK</CurrencyCoded> </Currency> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </UnitPrice> <PriceBasisQuantity> <Quantity> <QuantityValue>1</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> </PriceBasisQuantity> </Price> </ListOfPrice> <Tax> <TaxFunctionQualifierCoded>Tax</TaxFunctionQualifierCoded> <TaxCategoryCoded>StandardRate</TaxCategoryCoded> <TaxTypeCoded>ValueAddedTax</TaxTypeCoded> <TaxPercent>.00</TaxPercent> <TaxableAmount>20.00</TaxableAmount> <TaxAmount>.00</TaxAmount> </Tax> <TotalValue> <MonetaryValue> <MonetaryAmount>20.00</MonetaryAmount> </MonetaryValue> </TotalValue> </PricingDetail> <DeliveryDetail> <ListOfScheduleLine> <ScheduleLine> <Quantity> <QuantityValue>1</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> <RequestedDeliveryDate>20140904T00:00:00+01:00</RequestedDeliveryDate> </ScheduleLine> </ListOfScheduleLine> </DeliveryDetail> </ItemDetail> <ItemDetail> <BaseItemDetail> <LineItemNum> <BuyerLineItemNum>2</BuyerLineItemNum> </LineItemNum> <LineItemType> <LineItemTypeCoded>Item</LineItemTypeCoded> </LineItemType> <ItemIdentifiers> <PartNumbers> <SellerPartNumber> <PartNum> <PartID>9788258312007</PartID> </PartNum> </SellerPartNumber> <ManufacturerPartNumber> <PartID /> </ManufacturerPartNumber> </PartNumbers> <ItemDescription>Hovedtariffavtalen i staten 1. mai 2014 - 30. april 2016 (p.100kr)</ItemDescription> </ItemIdentifiers> <TotalQuantity> <Quantity> <QuantityValue>2</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> </TotalQuantity> <OffCatalogFlag>false</OffCatalogFlag> </BaseItemDetail> <PricingDetail> <ListOfPrice> <Price> <UnitPrice> <UnitPriceValue>100</UnitPriceValue> <Currency> <CurrencyCoded>NOK</CurrencyCoded> </Currency> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </UnitPrice> <PriceBasisQuantity> <Quantity> <QuantityValue>1</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> </PriceBasisQuantity> </Price> </ListOfPrice> <Tax> <TaxFunctionQualifierCoded>Tax</TaxFunctionQualifierCoded> <TaxCategoryCoded>StandardRate</TaxCategoryCoded> <TaxTypeCoded>ValueAddedTax</TaxTypeCoded> <TaxPercent>.00</TaxPercent> <TaxableAmount>100.00</TaxableAmount> <TaxAmount>.00</TaxAmount> </Tax> <TotalValue> <MonetaryValue> <MonetaryAmount>200.00</MonetaryAmount> </MonetaryValue> </TotalValue> </PricingDetail> <DeliveryDetail> <ListOfScheduleLine> <ScheduleLine> <Quantity> <QuantityValue>2</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> <RequestedDeliveryDate>20140904T00:00:00+01:00</RequestedDeliveryDate> </ScheduleLine> </ListOfScheduleLine> </DeliveryDetail> </ItemDetail> </ListOfItemDetail> </OrderDetail> <OrderSummary> <NumberOfLines>2</NumberOfLines> <TotalTax> <MonetaryValue> <MonetaryAmount>.00</MonetaryAmount> </MonetaryValue> </TotalTax> <TotalAmount> <MonetaryValue> <MonetaryAmount>220.00</MonetaryAmount> <Currency> <CurrencyCoded>NOK</CurrencyCoded> </Currency> </MonetaryValue> </TotalAmount> </OrderSummary> </Order> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Hi, I need to build my own xml validator and was wondering, what are some possible purposes of having multiple text nodes for a given parent node, I ask b/c while I was playing around with W3schools XML validator, I noticed it successfully validated the following: <?xml version="1.0" encoding="utf-8" ?> <note> <to>Joh</to> <from>Frank</from> <body>Hello world</body> Extra text node that is validated! </note> Anyone can help me? <?php $tbl_name="menu"; $kategorije = mysql_query("SELECT * FROM $tbl_name WHERE Left(menu_name, 1) BETWEEN 'A' AND 'M' ORDER BY menu_name ASC"); if (!$kategorije) { die("Database query failed: " . mysql_error()); } while ($row=mysql_fetch_array( $kategorije )) { echo "<div id=lista-header><h4>{$row["menu_name"]}</h4></div>"; $id_sub=$row['id_menu']; $podkategorije = mysql_query("SELECT * FROM submenu WHERE id_menu=$id_sub ORDER BY sub_name ASC", $connection); if (!$podkategorije) { die("Database query failed: " . mysql_error()); } echo "<ul class=\"pod\">"; while ($pod=mysql_fetch_array( $podkategorije )) { echo "<li><a href=index.php?=podkate?".$pod["id_sub"]." class=black>{$pod["sub_name"]}</a><hr size=1 align=left width=100px color=#cccccc></li>"; } echo "</ul>"; } ?> In this way, I get list with categories and hes subcategories. How to count how many subcategories have each categories, and count how many articles have each categories? Example (I wanna get this kind of look): Categories name (3) subcategoriesname (2) subcategoriesname (4) subcategoriesname (7) Categories name (5) subcategoriesname (1) subcategoriesname (14) subcategoriesname (9) subcategoriesname (2) subcategoriesname ( Categories name (2) subcategoriesname (28) subcategoriesname (17) Where the numbers represent how many categories and sub-items have articles good day dear experts,
<?php /** * OSM Overpass API with PHP SimpleXML / XPath * * PHP Version: 5.4 - Can be back-ported to 5.3 by using 5.3 Array-Syntax (not PHP 5.4's square brackets) */ // // 1.) Something is wrong an OSM Overpass API Endpoint // $Something is wrong = 'node ["addr:postcode"~"RM12"] (51.5557914,0.2118915,51.5673083,0.2369398)->.point; ( node (around.point:100000) ["amenity"~"school"]; way (around.point:100000) ["amenity"~"school"]; ); out;'; $context = stream_context_create(['http' => [ 'method' => 'POST', 'header' => ['Content-Type: application/x-www-form-urlencoded'], 'content' => 'data=' . urlencode($Something is wrong), ]]); # please do not stress this service, this example is for demonstration purposes only. $endpoint = 'http://overpass-api.de/api/interpreter'; libxml_set_streams_context($context); $start = microtime(true); $result = simplexml_load_file($endpoint); printf("Something is wrong returned %2\$d node(s) and took %1\$.5f seconds.\n\n", microtime(true) - $start, count($result->node)); // // 2.) Work with the XML Result // # get all school nodes with xpath $xpath = '//node[tag[@k = "amenity" and @v = "school"]]'; $schools = $result->xpath($xpath); printf("%d School(s) found:\n", count($schools)); foreach ($schools as $index => $school) { # Get the name of the school (if any), again with xpath list($name) = $school->xpath('tag[@k = "name"]/@v') + ['(unnamed)']; printf("#%02d: ID:%' -10s [%s,%s] %s\n", $index, $school['id'], $school['lat'], $school['lon'], $name); }
FATAL ERROR syntax error, unexpected 'is' (T_STRING) on line number 11
well at the moment i try to make up my mind what is going on here Hey guys! I have the following strange problem: Listing 1: echo $n; // Result is 20167 ! if($child->id == $n){ $image = array(); $image[] = '"' . $child->id . '"'; $image[] = '"' . $child->name . '"'; $image[] = '"' . $misc->clean_path($child->file) . '"'; $image[] = '"' . $child->file_name . '"'; $image[] = '"' . $child->file_type . '"'; $image[] = '"' . $path . '"'; $images[] = implode("\t", $image); } The if-statement is not true... so probably there's no $child->id with value 20167.... but watch this: Listing 2: if($child->id == 20167){ $image = array(); $image[] = '"' . $child->id . '"'; $image[] = '"' . $child->name . '"'; $image[] = '"' . $misc->clean_path($child->file) . '"'; $image[] = '"' . $child->file_name . '"'; $image[] = '"' . $child->file_type . '"'; $image[] = '"' . $path . '"'; $images[] = implode("\t", $image); } Now with the hard coded value 20167 the statement is true and gives one result.... Strange, isn't it? I placed the following three functions/test direct before the if-statement: var_dump($n); Result: NULL echo $n Result: 20167 echo "{$n}"; Result: I tested one function at a time. How can this happen? Thanks to all! :-) Hi, I am trying to work with this xml page: http://maps.google.com/maps/api/directions/xml?origin=m20%202nu&destination=m5%205hf&sensor=false public function LoadXml(){ $xml = simplexml_load_file("http://maps.google.com/maps/api/directions/xml?origin=m20%202nu&destination=m5%205hf&sensor=false"); foreach ($xml->xpath('//distance') as $distance): echo $distance->value->getName() . ": " . $distance->value . "<br />"; endforeach; echo "<BR>"; foreach($xml->xpath('//leg') as $address): echo "The start address is: ".$address-> start_address.$address. "<br />"; echo "The end address is: ".$address->end_address.$address; endforeach; } what this code does is echo out the following: Quote value: 102 value: 268 value: 701 value: 103 value: 4512 value: 275 value: 704 value: 1575 value: 64 value: 65 value: 1782 value: 313 value: 10464 The start address is: Manchester, Greater Manchester M20 2NU, UK The end address is: Salford M5 5HF, UK Now i don't need ALL the values, i only need the total value which is 10464. So is there a way to display the last child, or the final value? So all i want to show is value: 10464.. How can i access the final instance of the value? Thanks again Hi to all,
As per my client suggested, i need to change the info box background color for every info box (circular way). So i used the CSS3 pseudo nth-child algoritham to assign each info box background color with different background colors.
Here is my html code
<div class="row flexslider carousel" id="appList"> <ul class="slides"> <li> <div class="col-lg-3 col-md-6 col-sm-6"> <div class="info-box"> <img src="img/shortcuts/money.png" alt=""> <div class="count">1</div> <div class="title">New users</div> <div class="desc">Purchase</div> <div class="desc f-bold">Test</div> </div> </div> </li> <li> <div class="col-lg-3 col-md-6 col-sm-6"> <div class="info-box"> <img src="img/shortcuts/money.png" alt=""> <div class="count">2</div> <div class="title">New users</div> <div class="desc">Purchase</div> <div class="desc f-bold">Test</div> </div> </div> </li> <li> <div class="col-lg-3 col-md-6 col-sm-6"> <div class="info-box"> <img src="img/shortcuts/money.png" alt=""> <div class="count">3</div> <div class="title">New users</div> <div class="desc">Purchase</div> <div class="desc f-bold">Test</div> </div> </div> </li> <li> <div class="col-lg-3 col-md-6 col-sm-6"> <div class="info-box"> <img src="img/shortcuts/money.png" alt=""> <div class="count">4</div> <div class="title">New users</div> <div class="desc">Purchase</div> <div class="desc f-bold">Test</div> </div> </div> </li> <li> <div class="col-lg-3 col-md-6 col-sm-6"> <div class="info-box"> <img src="img/shortcuts/money.png" alt=""> <div class="count">5</div> <div class="title">New users</div> <div class="desc">Purchase</div> <div class="desc f-bold">Test</div> </div> </div> </li> </ul> </div>Here is CSS code .info-box { min-height: 140px; border: 1px solid black; margin-bottom: 30px; padding: 20px; color: white; -webkit-box-shadow: inset 0 0 1px 1px rgba(255, 255, 255, 0.35), 0 3px 1px -1px rgba(0, 0, 0, 0.1); -moz-box-shadow: inset 0 0 1px 1px rgba(255, 255, 255, 0.35), 0 3px 1px -1px rgba(0, 0, 0, 0.1); box-shadow: inset 0 0 1px 1px rgba(255, 255, 255, 0.35), 0 3px 1px -1px rgba(0, 0, 0, 0.1); } .info-box i { display: block; height: 100px; font-size: 60px; line-height: 100px; width: 100px; float: left; text-align: center; border-right: 2px solid rgba(255, 255, 255, 0.5); margin-right: 20px; padding-right: 20px; color: rgba(255, 255, 255, 0.75); } .info-box img { display: block; height: auto; font-size: 46px; line-height: 46px; width: auto; float: left; text-align: center; border-right: 2px solid rgba(255, 255, 255, 0.5); margin-right: 20px; padding-right: 20px; color: rgba(255, 255, 255, 0.75); } .info-box .count { margin-top: -10px; font-size: 34px; font-weight: 700; } .info-box .title { font-size: 12px; text-transform: uppercase; font-weight: 600; } .info-box .desc { margin-top: 10px; font-size: 12px; } #appList ul.slides li div div.info-box:nth-child(5n+1) { background: #fabb3d; border: 1px solid #f9aa0b; } #appList ul.slides li div div.info-box:nth-child(5n+2) { background: #ff5454; border: 1px solid #ff2121; } #appList ul.slides li div div.info-box:nth-child(5n+3) { background: #67c2ef; border: 1px solid #39afea; } #appList ul.slides li div div.info-box:nth-child(5n+4) { background: #79c447; border: 1px solid #61a434; } #appList ul.slides li div div.info-box:nth-child(5n) { background: #20a8d8; border: 1px solid #1985ac; }But when i tried with the above code, the info box only accepts (5n+1) CSS code. Can any one please suggest me the way to get the solution. I have the following result that I am getting from a source. Code: [Select] SimpleXMLElement Object ( [CategoryID] => 1 [Name] => Other [Order] => 0 [link] => http://www.link.com?sub=1 ) SimpleXMLElement Object ( [CategoryID] => 1233916011 [Name] => ceramic [Order] => 1 [ChildCategory] => SimpleXMLElement Object ( [CategoryID] => 1234016011 [Name] => dish [Order] => 1 ) [link] => http://www.link.com?sub=13476 ) SimpleXMLElement Object ( [CategoryID] => 1233917011 [Name] => laminate [Order] => 2 [link] => http://www.link.com?sub=98247 ) I need to get it into a database with the following structure Code: [Select] id categoryID cName cOrder clink cparent By using Code: [Select] foreach($this->resp->Store->CustomCategories->CustomCategory as $cat) { $sub = $cat->CategoryID; $ord = $cat->Order; $linkto = "$stlink?fsub=$fsub"; $nm = htmlspecialchars($cat->Name); $par=$cat->ChildCategory->Order; $query = "INSERT INTO Cat (categoryID,cName,cOrder,clink,cparent) VALUES ('$sub','$nm','$ord','$linkto','$par')"; $result = @mysql_query ($query); // Run the query. } I can get Code: [Select] id categoryID cName cOrder clink cparent 1 1 Other 0 http://www.link.com?sub=1 0 2 1233916011 ceramic 1 http://www.link.com?sub=13476 0 2 1233917011 laminate 2 http://www.link.com?sub=98247 0 But I need to get the ChildCategory in there w/ cparent like Code: [Select] id categoryID cName cOrder clink cparent 1 1 Other 0 http://www.link.com?sub=1 0 2 1233916011 ceramic 1 http://www.link.com?sub=13476 0 3 1234016011 dish 1 1 <--- like this 4 1233917011 laminate 2 http://www.link.com?sub=98247 0 any help appreciated... |