I'm trying to find a way to get information out of a database and use this information in a graph. Im using a libery (FusionCharts), this has some examples but not with data out of a database. So far i came up this this but im getting an error
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW)
The example im using is this one Example angulargauge
if ($result) {
$arrData6 = array(
"chart" => array
(
"caption" => "Sended mail",
"lowerlimit" => "0",
"upperlimit" => "100",
"lowerlimitdisplay" =>"0%",
"upperlimitdisplay" => "100%",
"palette" => "1",
"numbersuffix" => "%",
"tickvaluedistance" => "10",
"showvalue" => "0",
"gaugeinnerradius" => "0",
"bgcolor" => "FFFFFF",
"pivotfillcolor" => "333333",
"pivotradius" => "8",
"pivotfillmix" => "333333, 333333",
"pivotfilltype" => "radial",
"pivotfillratio"=> "0,100",
"showtickvalues"=> "1",
"showborder" => "0",
),
"colorRange" => array (
"color" => array
(
"minValue" => "0",
"maxValue" => "50",
"code" => "#e44a00"
),
(
"minValue" => "50",
"maxValue" => "75",
"code" => "#f8bd19"
),
(
"minValue" => "75",
"maxValue" => "100",
"code" => "#6baa01"
)
),
"dials" => array (
"dial" => array (
"value" => "$precentage"
)
)
);
$arrData6["data"] = array();
$jsonEncodedData6 = json_encode($arrData6);
$angularChart = new FusionCharts("AngularGauge", "chart4" , "100%", "200", "chart-5", "json", $jsonEncodedData6);
// Render the chart
$angularChart->render();
}
I can up with this by using the information on the page but since this one got more informatiesets (chart,dials and colors) I haven't been able to figure out how to do it yet.Database how to explaination i used
The $percentage is the result of the total - the not sended mail
Related
I have a woocommerce (wordpress) up to date, with over 10k products which I need to create variations for, there are four kinds of variations, two are hardcopy with inventory control, the other two variation of the products does not need inventory control.
I have check out so many various ways people have created programmatically variations and attempted their scripts on a dev site, that I am starting to get bug eyed.
<?php
require_once('wp-load.php'); // load the wordpress core
require_once('functions.php') ; // custom functions to grab related data from the wpdb
$import_id = GetTheNextProduct(); // non-wordpress database
$is_variable_product = CheckIfVariable($import_id) ;
$post_id = GetRelatedWPDI($import_id); // returns related word press post `ID` of the product
// ... other variables are set in the same way... ie: $sku = GetSKU($import_id) ;
// the problem I am having is getting the current variation array into woocommerce variations,
// I've been able to do everything else.
if($is_variable_product == 1) {
$variations = GetVariations($import_id) ;
// woocommerce proper way to create variations....????
}
/* out example of $variations...
$variations = array(
"0" => array(
"ProductType" => "Small PDF",
"filepath" => "/path/to/pdf/file.pdf",
"filename" => "file.pdf",
"price" => "5.00",
"_visibility" => "visible",
"_stock_status" => "instock",
"_downloadable" => "yes",
"_weight" => "",
"_length" => "",
"_width" => "",
"_height" => "",
"_width" => "",
"inventory" => "unlimited",
"_sku" => "parent",
),
"1" => array(
"ProductType" => "Large PDF",
"filepath" => "/path/to/pdf/file-large.pdf",
"filename" => "file-large.pdf",
"price" => "10.00",
"_visibility" => "visible",
"_stock_status" => "instock",
"_downloadable" => "yes",
"_weight" => "",
"_length" => "",
"_width" => "",
"_height" => "",
"_width" => "",
"inventory" => "unlimited",
"_sku" => "parent",
),
"2" => array(
"ProductType" => "Small Hardcopy",
"filepath" => "",
"filename" => "",
"price" => "15.00",
"_visibility" => "visible",
"_stock_status" => "instock",
"_downloadable" => "yes",
"_weight" => "0.5",
"_length" => "",
"_width" => "8",
"_height" => "11",
"_width" => "",
"inventory" => "123",
"_sku" => "parent",
),
"4" => array(
"ProductType" => "Large Hardcopy",
"filepath" => "",
"filename" => "",
"price" => "20.00",
"_visibility" => "visible",
"_stock_status" => "instock",
"_downloadable" => "yes",
"_weight" => "0.5",
"_length" => "",
"_width" => "8",
"_height" => "11",
"_width" => "",
"inventory" => "456",
"_sku" => "parent",
),
)
*/
update_post_meta( $post_id, '_sku', $sku);
update_post_meta( $post_id,'_visibility','visible');
wp_set_object_terms($post_id, 'variable', 'product_type');
// do something here to the current $variations array variable to...
$variation_id = wp_insert_post( $variation_post );
$variation = new WC_Product_Variation( $variation_id );
foreach($variations as $vars_sub){
foreach($vars_sub as $key => $value) {
update_post_meta( $variation_id, 'attribute_'.$key, $value );
}
}
I've read, tried, so many of the script suggestions within stack, some which have helped a lot with simple products that remain simple... but this one has me stumped.
I solved this issue by leveraging WC's REST API and Python. My script is here: https://gist.github.com/Antebios/f53807040247b536e1674758a400dc45
Converting the product type from 'Simple' to Variable was easy, it was adding the variations that was tricky. I am doing an iteration loop and creating a variation from an array, I also check if the variation already exists so there are no duplicate variations. Have a look.
I am trying to print data in json format from my 'data.json' file. With my php file (alldata.php), I could get all data (arrays) pretty printed. But where I want you to help me is how to get a specific array name and it objects/content.
My alldata.php looks like this:
{
"players": [
{
"name": "Marcos Alonso",
"position": "Left-Back",
"nationality": "Spain",
"marketValue": "9,000,000 €",
"created": "2017-04-15 10:04:58"
}],
"articles": [
{
"author": "Stephen Walter",
"title": "Disruptive stag party revellers thrown off plane at Manchester Airport",
"url": "http://www.telegraph.co.uk/news/2017/04/15/disruptive-stag-party-revellers-thrown-plane-manchester-airport/",
"publishedAt": "2017-04-15T09:25:10Z"
}],
land": [
{
"state": "Somewhr",
"found": "1889",
"area": "6,812",
"empl": "1,325",
"ppl": "16,842"
}]
}
In php, how can I get an array e.g "players" with the content by using url such as 'alldata.php?search=players'
Here is a code sample....
//get content of the JSON API using file_get_contents()
$url = ('myJson.json');
$jsondata = file_get_contents($url);
//convert json object to php associative array
$data = json_decode($jsondata, true);
what do I do here to query the data.json file for a specific array?????
header('Content-Type: application/json; charset=UTF-8');
$json_string = json_encode($????????????, JSON_PRETTY_PRINT);
print $json_string;
Thanks
If I properly understood what you mean, and if your array has always the same tree, this wilp help you access the data :
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$array = array(
0 => array(
"players" => array(
"name" => "Marcos Alonso",
"position" => "Left-Back",
"nationality" => "Spain",
"marketValue" => "9,000,000 €",
"created" => "2017-04-15 10:04:58"
),
"articles" => array(
"author" => "Stephen Walter",
"title" => "Disruptive stag party revellers thrown off plane at Manchester Airport",
"url" => "http://www.telegraph.co.uk/news/2017/04/15/",
"publishedAt" => "2017-04-15T09:25:10Z"
),
"land" => array(
"state" => "Somewhr",
"found" => "1889",
"area" => "6,812",
"empl" => "1,325",
"ppl" => "16,842"
)
),
1 => array(
"players" => array(
"name" => "Sebastian Vettel",
"position" => "Driver",
"nationality" => "Germany",
"marketValue" => "9,000,000 €",
"created" => "2013-03-15 11:04:52"
),
"articles" => array(
"author" => "Stephen Walter",
"title" => "Disruptive stag party revellers thrown off plane at Manchester Airport",
"url" => "http://www.telegraph.co.uk/news/2017/04/15/",
"publishedAt" => "2017-04-15T09:25:10Z"
),
"land" => array(
"state" => "Somewhr",
"found" => "1889",
"area" => "6,812",
"empl" => "1,325",
"ppl" => "16,842"
)
)
);
/* end of array */
$data1 = json_encode($array); /* just checking - not needed after that */
$data = json_decode($data1, true); /* just checking - not needed after that */
$needle = "articles"; /* should be $needle = $_GET['search']; and checked before use */
//print_r($data); /* just checking */
foreach($data as $value){ /* we access 1st level */
echo '** Needle is: '.$needle.' **<br/>';
foreach($value[$needle] as $sub_key => $sub_data){ /* we access 2nd level */
echo $sub_key.'-->'.$sub_data.'<br/>'; }
}
?>
Once you access the data, you can easily do what you want with it...
Good morning,
I have a very specific example that I am trying to implement. The goal is to get the following JSON end result.
{
merchantId :"123456",
tenderType :"Card",
amount :"0.02",
account :
{
number : "4111",
expiryMonth : "02",
expiryyear : "2016",
cvv : "019",
avsZip : "30014",
avsStreet: "2001 Main"
}
}
I am familiar with json_encode and I have can get this done for the 1st 3 parameters with the following code:
json_encode(
array(
"merchantId" => "123456",
"tenderType" => "Card",
"amount" => "0.02"
)
}
but the 4th parameter (account) is getting me stuck. Can anybody explain to me how to incorporate the 4th parameter that is itself an array.
George
It should just be a nested associative array:
json_encode(
array(
"merchantId" => "123456",
"tenderType" => "Card",
"amount" => "0.02",
"account" => array(
"number" => "4111",
"expiryMonth" => "02",
"expiryyear" => "2016",
"cvv " => "019",
"avsZip" => "30014",
"avsStreet" => "2001 Main"
)
)
)
Looking for some help with looping through a multidimensional/associative array in PHP. Essentially, I need to loop through and output the certain key values in a table. Not having much luck.
Here is a sample of my array.
$myarray = array(
"body" => array(
"0" => array(
"machine" => array(
"id" => "1",
"name" => "macbookpro",
"description" => "laptop machine",
"state" => "reserved",
"state_since" => "2013-08-28 12:05:00",
"queue_snapshot" => array(
"time" => "2013-08-01 12:00:00",
"jobs" => "450",
"jobs_available" => "90",
"cputime_running" => "00:01:00",
"cputime_eligible" => "00:90:00",
"cputime_block" => " 90:00:00",
)
)
),
"1" => array(
"machine" => array(
"id" => "2",
"name" => "ipad",
"description" => "tablet machine",
"state" => "available",
"state_since" => "2013-08-28 12:05:00",
"queue_snapshot" => array(
"time" => "2013-08-01 12:00:00",
"jobs" => "50",
"jobs_available" => "20",
"cputime_running" => "00:05:00",
"cputime_eligible" => "00:12:00",
"cputime_block" => " 00:10:00",
)
)
)
));
I have some values in this array that will need to be accessed later so I only need to be able to access particular values in order to create this table. Needs to output like this....
Machine Name | Description | State | Jobs | Jobs Available |
macbookpro laptop machine reserved 450 90
ipad tablet machine available 50 20
Untestet on the fly
<?php
if(isset($myarray['body']) && is_array($myarray['body']))
foreach($myarray['body'] as $id=>$arr) {
$name = $arr['name'];
$description = $arr['description'];
$jobs = $arr['queue_snapshot']['jobs'];
$jobs_available = $arr['queue_snapshot']['jobs_available'];
echo "<br>$name $description $jobs $jobs_available";
}
?>
So I'm back again. My problem is this:
I have an array of Docusign Templates from checkboxes in a Codeigniter view:
<?php
echo form_open('create_envelope');
foreach ($response["envelopeTemplates"] as $envelopeTemplate) { ?>
<li><?php echo form_checkbox('templatearray[]', $envelopeTemplate["templateId"], FALSE), $envelopeTemplate["name"]; ?></li>
<?php } ?>
What I'm trying to do is add the templates to our REST Header request:
$data = array(
"accountId" => $accountId,
"emailSubject" => "Hello World!",
"emailBlurb" => "This comes from PHP",
"templateId" => "ID from template array here",
"templateRoles" => array(
array(
"tabs" => array(
"textTabs" => array (
array (
"tabLabel" => "lic_num",
"value" => "$license_number"
),
array (
"tabLabel" => "ubi_num",
"value" => "$ubi_number"
),
array (
"tabLabel" => "tra_nam",
"value" => "$trade_name"
)
)
),
"email" => "$applicant_email",
"name" => "$applicant_name",
"roleName" => "Applicant"
)
),
"status" => "sent"
);
Is this possible?
EDIT: So I got it to work using loops to get my data in the request, but I'm running into an interesting problem. If I put one or two templates in the envelope, it sends fine. If I put more than two in, it duplicates the templates. Here is my code for the complicated loops:
$compTempArray = array();
$applicant_name = $this->input->post("applicant_name");
$applicant_email = $this->input->post("applicant_email");
$license_number = $this->input->post("license_number");
$ubi_number = $this->input->post("ubi_number");
$trade_name = $this->input->post("trade_name");
foreach($hello as $key => $value) {
if(sizeof($hello) > 1) {
for($i = 1; $i < sizeof($hello); $i++) {
$compTempArray[] = array("serverTemplates" => array(
array(
"sequence" => $i,
"templateId" => $value
)
),
"inlineTemplates" => array(
array(
"sequence" => $i,
"recipients" => array(
"signers" => array(
array(
"tabs" => array(
"textTabs" => array (
array ("tabLabel" => "lic_num", "value" => $license_number),
array ("tabLabel" => "ubi_num", "value" => $ubi_number),
array ("tabLabel" => "tra_nam", "value" => $trade_name)
)
),
"email" => "*********#*****.com",
"name" => $applicant_name,
"recipientId" => "1",
"roleName" => "Applicant"
),
)
)
)
));
}
$data = array("accountId" => $accountId,
"emailSubject" => "Hello World!",
"emailBlurb" => "This comes from PHP",
"compositeTemplates" => $compTempArray,
"status" => "sent");
} else {
$data = array("accountId" => $accountId,
"emailSubject" => "Hello World!",
"emailBlurb" => "This comes from PHP",
"templateId" => "$value",
"templateRoles" => array(
array(
"tabs" => array(
"textTabs" => array (
array ("tabLabel" => "lic_num", "value" => $license_number),
array ("tabLabel" => "ubi_num", "value" => $ubi_number),
array ("tabLabel" => "tra_nam", "value" => $trade_name)
)
),
"email" => "*********#*****.com",
"name" => $applicant_name,
"roleName" => "Applicant"
)
),
"status" => "sent");
}
}
Any idea why it would do this?
NEW EDIT: Update on this weirdness: one to two - one copy of each template, three - it doubles the amount of each template, four - it triples the amount, five - it quadruples the amount.
NEWEST EDIT: So as it turns out, it was the for loop that I was using to try and increment the sequence. I got rid of the loop and hardcoded the sequence to 1. That fixed it.
To apply multiple templates to a single envelope you'll need to use the compositeTemplates structure.
compositeTemplates can get complex very quickly but they do allow for great flexibility and functionality for your envelopes. The API documentation is the best place to read about compositeTemplates but as previously mentioned the April 2012 Templates Webinar is also a good resource. The third example provides a basic use of compositeTemplates in that it shows you how to combine two server templates into one single envelope. You can use that as a base for your JSON.
To apply 2 server templates to a single envelope it uses the following JSON:
{
"emailSubject": "DocuSign Templates Webinar - Example 3",
"emailBlurb": "Example #3 - Composite Templates",
"status": "sent",
"compositeTemplates": [
{
"serverTemplates": [
{
"sequence": "1",
"templateId": "55A80182-2E9F-435D-9B16-FD1E1C0F9D74"
}
],
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"email": "firstrecipient#gmail.com",
"name": "John Doe",
"recipientId": "1",
"roleName": "RoleOne"
}
]
}
}
]
},
{
"serverTemplates": [
{
"sequence": "2",
"templateId": "44D9E888-3D86-4186-8EE9-7071BC87A0DA"
}
],
"inlineTemplates": [
{
"sequence": "2",
"recipients": {
"signers": [
{
"email": "secondrecipient#gmail.com",
"name": "Jane Doe",
"recipientId": "1",
"roleName": "RoleOne"
}
]
}
}
]
}
]
}
Note that the sequence value for each template determines the order of template application to the envelope. So in other words, the sequence value determines the document order, but since the templates might have matching/conflicting info (in terms of template roles for instance) the sequence value might also affect the end result of the envelope.