shingionline
-
Posts
5 -
Joined
-
Last visited
Never
Posts posted by shingionline
-
-
You're leaving out the PRODUCTS layer.
Got it! Thank you very much guys, everything is working perfectly
-
I was going to give you the easy answer, but I'm very sure that it won't work in all circumstances.
Comes from XML, right? The problem is that there might be multiple PRODUCTs inside that PRODUCTS, but because PHP doesn't know that it assumes (in this instance) that there's only one. The array will look different in the two cases. However there's that NUMRETURNED you can use to get a proper array.
$products = ($arr["WHMCSAPI"]["NUMRETURNED"] == 1 ? array($arr["WHMCSAPI"]["PRODUCTS"]["PRODUCT"]) : $arr["WHMCSAPI"]["PRODUCTS"]); foreach ($products as $p) { echo "Name: ", $p["NAME"], "<br />\n"; }
Thanks for your help, yes this is coming from XML. The simple solution will be fine, there will only ever be 1 PRODUCT. The code below is fine for first level values
echo $arr['WHMCSAPI']['DOMAIN'];
but when i try to get [uSERNAME] with
echo $arr['WHMCSAPI']['PRODUCT']['USERNAME'];
i get the error "Undefined index: PRODUCT"
-
You can do this by echoing them.
e.g. to echo the value for "result"
echo $arr[WHMCSAPI][RESULT];
Thanks, this works well for the first level eg:
echo $arr['WHMCSAPI']['DOMAIN'];
How can i get to the [uSERNAME] which is on the second level. The code below
echo $arr['WHMCSAPI']['PRODUCT']['USERNAME'];
gives the error message "Undefined index: PRODUCT"
-
Hi Guys,
I have an array
$arr
When i run this function
print_r($arr)
I get the output below:-
--------------------------------
Array ( [WHMCSAPI] => Array ( [ACTION] => getclientsproducts [RESULT] => success [CLIENTID] => 87 [PID] => 13 [DOMAIN] => dfgbhcgnd.com [TOTALRESULTS] => 1 [sTARTNUMBER] => 0 [NUMRETURNED] => 1 [PRODUCTS] => Array ( [PRODUCT] => Array ( [iD] => 196 [CLIENTID] => 87 [ORDERID] => 218 [PID] => 13 [REGDATE] => 2011-12-07 [NAME] => Walderizer [DOMAIN] => dfgbhcgnd.com [DEDICATEDIP] => [sERVERID] => 3 [FIRSTPAYMENTAMOUNT] => 55.00 [RECURRINGAMOUNT] => 55.00 [PAYMENTMETHOD] => banktransfer [PAYMENTMETHODNAME] => Bank Transfer [bILLINGCYCLE] => Monthly [NEXTDUEDATE] => 2011-12-07 [sTATUS] => Active [uSERNAME] => vitaforiz [PASSWORD] => ghTfg476fg [sUBSCRIPTIONID] => [LASTUPDATE] => 0000-00-00 00:00:00 [CUSTOMFIELDS] => Array ( [CUSTOMFIELD] => Array ( [NAME] => IP Address [VALUE] => ) ) [CONFIGOPTIONS] => ) ) ) )
---------------------------------
My question is, how can i print only certain parts of the data rather than printing the whole array. For example i only want to echo the values for [NAME], [uSERNAME], [PASSWORD] and [NEXTDUEDATE] from the [PRODUCT] part of the array
Thanks in advance
The best PHP start
in PHP Coding Help
Posted
The fact that you have a project to work on is a great start. I would highly recommend you have a look into the Codeigniter PHP framework it has been the best decision i ever made in my quest to learn PHP. Codeigniter has a very extensive user guide within no time you'll get the hang of it. All the best