Here are list of arrays which i echoed in
Array
(
[CustomerID] => manish14
[TicketID] => 45691
[TicketNumber] => 1045828
[CustomerUserID] =>
)
Array
(
[CustomerID] => ghisingraaz#gmail.com
[TicketID] => 45686
[TicketNumber] => 1045823
[CustomerUserID] => ghisingraaz#gmail.com
)
Array
(
[CustomerID] => ranjana#classic.com.np
[TicketID] => 45661
[TicketNumber] => 1045798
[CustomerUserID] => ranjana#classic.com.np
)
........
........
........
I want to display customerID , TicketID and TicketNumber of each array in a table format. How can i retrieve those values. I have this in multiple foreach loop thats why i am having problem getting those values.
Here is my code incase anyone wants to see. phpfiddle.org/main/code/wb4u-nrsj
You can find my code in this PhpFiddle.
<?PHP
error_reporting(0);
//////// OTRS specific information ////////
$url = "https://otrs.classic.com.np/otrs/rpc.pl"; //// URL for OTRS server
$username = "ctdeveloper"; //// SOAP username set in sysconfig
$password = "ctdeveloper"; //// SOAP password set in sysconfig
$TicketID = $_GET['id'];
########################################################################
#### You don't have to change anything below here, although you can ####
########################################################################
#### Initialize new client session ####
echo "<table><tr><th>CustomerID</th><th>TicketID</th><th>TicketNumber</th></tr>";
$client = new SoapClient(
null,
array(
'location' => $url,
'uri' => "Core",
'trace' => 1,
'login' => $username,
'password' => $password,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED
)
);
#### Initialize new client session ####
$client = new SoapClient(
null,
array(
'location' => $url,
'uri' => "Core",
'trace' => 1,
'login' => $username,
'password' => $password,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED
)
);
$queues = array(1 => "Postmaster",
2 => "Raw",
3 => "Junk",
4 => "Retail Support",
5 => "Enterprise Support",
6 => "Sales",
7 => "Marketing",
8 => "Fiber Survey",
9 => "Fiber Support",
10 => "Billing",
11 => "NOC",
12 => "Wireless Support",
13 => "Core-Tasks",
14 => "Chitwan",
15 => "Developer",
16 => "Operations",
17 => "Administration",
18 => "Hetauda",
19 => "Business",
20 => "Info",
21 => "Corporate",
22 => "Wireless Survey",
23 => "Recovery",
24 => "L2-Support",
);
foreach ($queues as $queue_number => $queue_name) {
#### Create and send the SOAP Function Call ####
$TicketDetail_search = $client->__soapCall("Dispatch",
array($username, $password,
"TicketObject", "TicketSearch",
"Result", "ARRAY",
"UserID", 1,
"QueueIDs", array($queue_number),
"StateType", "open"
));
// REMOVE s-gensym
$ticketInfo = array();
if ($TicketDetail_search) {
foreach ($TicketDetail_search as $name => $value){
if (false !== strpos($name, "s-gensym"))
{
$ticketInfo[] = $value;
}
}
}
foreach($ticketInfo as $TicketID)
{
$TicketDetail_get = $client->__soapCall("Dispatch",
array($username, $password,
"TicketObject", "TicketGet",
"TicketID", $TicketID,
));
foreach($TicketDetail_get as $t)
{
$ticketInfo1 = array();
$i = 0;
foreach ($TicketDetail_get as $name => $value){ // explode the xml response
if (false !== strpos($name, "s-gensym")){
$temp[$i] = $value;
if($i > 0) {
$v = $temp[$i-1];
if($i % 2 != 0){
$ticketInfo1[$v] = $value;
}
}
$i++;
}
}
}
echo "<tr>";
echo "<td>" . $ticketInfo1['CustomerID'] . "</td>";
echo "<td>" . $ticketInfo1['TicketID'] . "</td>";
echo "<td>" . $ticketInfo1['TicketNumber'] . "</td>";
echo "</tr>";
}
}
echo "</table>";
?>
Is this what you are looking for ?
Related
Looking for some advice.
Trying to return a long query with around 65,000 results that has a lot of aggeration on the server-side. Takes around 16 seconds to return all the data.
This is what I have so far.
It's returning the query results but never seems to store in Memcached.
If I print $cached_data, it always says false. Thank you.
<?php
header('Content-Type: application/json');
include('pdo.php');
$memcache = new Memcache();
$memcache->addServer("127.0.0.1", 11211);
$query = "SELECT TOP 5000 Snumber,Number,Name,Status,dials,Size,Y04,Y05,PD0405,Y06,PD0506,Y07,PD0607,Y08,PD0708,Y09,PD0809,Y10,PD0910,Y11,PD1011,Y12,PD1112,Y13,PD1213,Y14,PD1314,Y15,PD1415,Y16,PD1516,Y17,PD1617,Y18,PD1718,Y19,PD1819,Y20,PD1920 FROM table ORDER BY Snumber";
$key = md5($query);
$cached_data = $memcache->get($key);
$response = [];
if ($cached_data != null) {
$result = $cached_data;
} else {
$statement = $conn->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$memcache->set($key, $result);
}
foreach ($result as $row) {
$output[] = array(
'Snumber' => $row['Snumber'],
'MeterNumber' => $row['Number'],
'Account' => $row['Name'],
'Status' => $row['Status'],
'dialsHI' => $row['dials'],
'MeterSize' => $row['Size'],
'Y04' => $row['Y04'],
'Y05' => $row['Y05'],
'PD0405' => $row['PD0405'],
'Y06' => $row['Y06'],
'PD0506' => $row['PD0506'],
'Y07' => $row['Y07'],
'PD0607' => $row['PD0607'],
'Y08' => $row['Y08'],
'PD0708' => $row['PD0708'],
'Y09' => $row['Y09'],
'PD0809' => $row['PD0809'],
'Y10' => $row['Y10'],
'PD0910' => $row['PD0910'],
'Y11' => $row['Y11'],
'PD1011' => $row['PD1011'],
'Y12' => $row['Y12'],
'PD1112' => $row['PD1112'],
'Y13' => $row['Y13'],
'PD1213' => $row['PD1213'],
'Y14' => $row['Y14'],
'PD1314' => $row['PD1314'],
'Y15' => $row['Y15'],
'PD1415' => $row['PD1415'],
'Y16' => $row['Y16'],
'PD1516' => $row['PD1516'],
'Y17' => $row['Y17'],
'PD1617' => $row['PD1617'],
'Y18' => $row['Y18'],
'PD1718' => $row['PD1718'],
'Y19' => $row['Y19'],
'PD1819' => $row['PD1819'],
'Y20' => $row['Y20'],
'PD1920' => $row['PD1920']);
}
echo json_encode($output, JSON_PRETTY_PRINT);
i have 2 products in my cart session. and want me to combine in array data_order. but read only 1 product. actually this data I will send in an email so from that I make the format of the data like this.
my controller :
foreach ($this->cart->contents() as $item){
if($item['diskon'] == "0"){
$harga_before = $item['before'];
$harga_after = $item['price'];
}else{
$harga_before = $item['before'];
$harga_after = $item['price'];
}
foreach ($this->cart->product_options($item['rowid']) as $option_name => $option_value){
if(empty($option_value)){
$option_size = "";
$option_color = "";
}else{
$option = $item['options'];
$option_size = $option['Size'];
$option_color = $option['Warna'];
}
}
$data = array(
'inv' => $invoice,
'tglOrdercs' => date('d F Y H:i:s'),
'tglExp' => $date_maju,
'nmlkp' => $nmlkpi,
'almtkp' => $address,
'noTelp' => $notelp271,
'methode' => $method,
'bnk_option' => $banking_select,
'data_order' => array(
'nama_produk' => $item['name'],
'artikel' => $item['artikel'],
'diskon' => $item['diskon'],
'ukuran' => $option_size,
'warna' => $option_color,
'qty' => $item['qty'],
'harga_fix' => $harga_after,
'harga_before' => $harga_before,
),
);
}
my result :
Array(
[inv] => STJOHB9261JR
[tglOrdercs] => 28 September 2017 11:23:33
[tglExp] => 28 September 2017 21:23:33
[nmlkp] => danny setyawan
[almtkp] => Perum puspa sari H22 sidoarjo
[noTelp] => 089263423647
[methode] => Transfer
[bnk_option] => Bank BNI
[data_order] => Array
(
[nama_produk] => Sonic TL Brown
[artikel] => CH2002-831
[diskon] => 40
[ukuran] => 39
[warna] => Coklat
[qty] => 2
[harga_fix] => 125340
[harga_before] => 208900
)
)
ignore ">", this result from browser console.
I have an array:
$settings = array(
'name' => array(
0 => 'Large Pouch',
1 => 'XL Pouch'
),
'size' => array(
0 => '9x14',
1 => '12x18'
),
'weight' => array(
0 => '10',
1 => '20'
),
'metro_manila_price' => array(
0 => '59',
1 => '79'
),
'luzvimin_price' => array(
0 => '89',
1 => '139'
)
);
I wanted to put the values from that array to one array. $shipping_options with format of
for example:
$shipping_options = array(
'0' => 'Large Pouch 9x14 - $59',
'1' => 'XL Pouch 12x18 - $79'
);
How to program this?
You could write a loop:
$shipping_options = array();
foreach ($settings['name'] as $key => $value) {
$value = sprintf('%s(%s) - $%s',
$value,
$settings['size'][$key],
$settings['metro_manila_price'][$key]);
$shipping_options[$key] = $value;
}
try this one
echo "<pre>";
$size = count($settings['name']);
$shipping_options = array();
for($i=0; $i<$size; $i++)
{
$shipping_options[$i] = $settings['name'][$i]."(".$settings['size'][$i].") - $".$settings['metro_manila_price'][$i];
}
print_r($shipping_options);
You can try this
foreach ($settings['name'] as $key => $value) {
$shipping_options[$key] = $settings['name'][$key] . " " . $settings['size'][$key] . " - $" . $settings['metro_manila_price'][$key];
}
I check every variable, but each one is echoing a verified result, so the problem is in the array. When I try to echo the full list of 56 values, I just get 11.
All variables are SET before, and i check for example if i echo $uno, i get a value of 12.. so why isnt that value on the array.
Here is my code..
$items = array(
$uno => "item1",
$dos => "item2",
$tres => "item3",
$cuatro => "item4",
$cinco => "item5",
$seis => "item6",
$siete => "item7",
$ocho => "item8",
$nueve => "item9",
$diez => "item10",
$once => "item11",
$doce => "item12",
$trece => "item13",
$catorce => "item14",
$quince => "item15",
$dieciseis => "item16",
$diecisiete => "item17",
$dieciocho => "item18",
$diecinueve => "item19",
$veinte => "item20",
$veintiuno => "item21",
$veintidos => "item22",
$veintitres => "item23",
$veinticuatro => "item24",
$veinticinco => "item25",
$veintiseis => "item26",
$veintisiete => "item27",
$veintiocho => "item28",
$veintinueve => "item29",
$treinta => "item30",
$treintayuno => "item31",
$treintaydos => "item32",
$treintaytres => "item33",
$treintaycuatro => "item34",
$treintaycinco => "item35",
$treintayseis => "item36",
$treintaysiete => "item37",
$treintayocho => "item38",
$treintaynueve => "item39",
$cuarenta => "item40",
$cuarentayuno => "item41",
$cuarentaydos => "item42",
$cuarentaytres => "item43",
$cuarentaycuatro => "item44",
$cuarentaycinco => "item45",
$cuarentayseis => "item46",
$cuarentaysiete => "item47",
$cuarentayocho => "item48",
$cuarentaynueve => "item49",
$cincuenta => "item50",
$cincuentayuno => "item51",
$cincuentaydos => "item52",
$cincuentaytres => "item53",
$cincuentaycuatro => "item54",
$cincuentaycinco => "item55",
$cincuentayseis => "item56",
);
The PHP CODE
<?PHP
echo "<strong>Original</strong><br />";
foreach($items as $k => $v){
echo $k . " = " . $v . "<br />";
}
asort($items);
echo "<strong>Ascending Sort</strong><br />";
foreach($items as $k => $v){
echo $k . " = " . $v . "<br />";
}
arsort($items);
echo "<strong>Descending Sort</strong><br />";
foreach($items as $k => $v){
echo $k . " = " . $v . "<br />";
}
?>
I get this as output..
Original
11 = item30
5 = item35
12 = item20
8 = item42
7 = item45
4 = item44
6 = item47
9 = item41
10 = item37
2 = item46
0 = item56
Ascending Sort
12 = item20
11 = item30
5 = item35
10 = item37
9 = item41
8 = item42
4 = item44
7 = item45
2 = item46
6 = item47
0 = item56
Descending Sort
0 = item56
6 = item47
2 = item46
7 = item45
4 = item44
8 = item42
9 = item41
10 = item37
5 = item35
11 = item30
12 = item20
Array keys must be unique. So, use itemNN for it.
$items = array(
"item1" => $uno,
"item2" => $dos,
"item3" => $tres,
...
Or even do not use string for keys
$items = array(
1 => $uno,
2 => $dos,
3 => $tres,
...
Or even like this
$items = array(
1 => $uno,
$dos,
$tres,
...
This might be very silly but we have not been able to do this .
We are trying to insert an array into a php file . However we are able to insert the array into a php file but the format is not as desired . We have 2 files .
File1.php
<?php
include_once("../dc/dcCommonLib.php");
include_once("../dc/persistence/UserData.php");
require_once("../../lib/include/connect.inc.php");
$_SESSION["survey"] = "BestBuyAug2012";
$idLink = dbconnect($_SESSION["survey"]);
$surveyWidget = rendererSurveyLoadHandler();
setDataToSession("surveywidget",$surveyWidget);
$userData = &UserData::getInstance();
$userData->setSurvey($surveyWidget);
saveFkidsToOidToFkidMappingArray($userData->OidToFkidMapping);
// prepare demo array
prepareItemArray($userData->OidToFkidMapping["Demographic"]["Q"],$demo,"b");
// prepare item array
prepareItemArray($userData->OidToFkidMapping["Default"]["Q"],$item,"i");
prepareItemArray($userData->OidToFkidMapping["Default"]["M"],$item,"i");
// prepare comment array
prepareCommentArray($userData->OidToFkidMapping["Comment"]["C"],$comment);
if(!function_exists('file_put_contents')) {
function file_put_contents($filename, $data,$type, $file_append = false) {
$fp = fopen($filename, (!$file_append ? 'w+' : 'a+'));
if(!$fp) {
trigger_error('file_put_contents cannot write in file.', E_USER_ERROR);
return;
}
if($type){
$count = count($data);
$i = 1;
//loop through your type array and append comma , to each except last
foreach($data as $key=>$val) {
//if we are before last key, append comma
if($i < $count)
$data[$key] .= ',';
$i++;
}
//run same preg_replace as before
$data2 = preg_replace('/[\[\]]/','"',print_r($data,TRUE));
//write to file
fputs($fp, "$" . $type . " = " . print_r($data2,TRUE));
} else {
fputs($fp, print_r($data, TRUE));
}
fclose($fp);
}
}
print("Strart writting ...................");
file_put_contents("staticSurveyDataFileTest.php", "<?php\n","",true);
file_put_contents("staticSurveyDataFileTest.php", $item,"itemFkids",true);
file_put_contents("staticSurveyDataFileTest.php", $demo,"demoFkids",true);
file_put_contents("staticSurveyDataFileTest.php", $comment,"commentFkids",true);
file_put_contents("staticSurveyDataFileTest.php", "?>","",true);
print("written ...");
function prepareItemArray($userDataArray, &$item, $itemStr) {
if(is_array($userDataArray)) {
foreach($userDataArray as $questId=>$respGrp) {
$selectionGrp=array_unique($respGrp);
if(count($selectionGrp)==1) {
$respGrpId=key($respGrp);
$respId = key($respGrp[$respGrpId]);
$item[$questId."_".key($respGrp)]=$itemStr.$respGrp[$respGrpId][$respId];
}else {
foreach ($respGrp as $respGrpId=>$resp) {
$respGrp[$respGrpId]=$itemStr.$resp;
}
$item[$questId."_".key($respGrp)]=$respGrp;
}
}
}
}
function prepareCommentArray($userDataArray, &$item) {
if(is_array($userDataArray)) {
foreach($userDataArray as $questId=>$respGrp) {
$selectionGrp=array_unique($respGrp);
if(count($selectionGrp)==1) {
$respGrpId=key($respGrp);
$item[$questId."_".key($respGrp)]=$respGrp[$respGrpId]["fk_id"];
}
}
}
}
?>
The array from this file is inserted into staticSurveyDataFileTest.php
staticSurveyDataFileTest.php
<?php
$itemFkids = Array
(
"203_19" => i27,//double quotes missing for all the lines . See below for desired output//
"207_22" => i28,
"357_22" => i99,
"370_70" => i104,
"377_72" => i105,
"140_8" => i1,
"141_8" => i2,
"142_8" => i3,
"143_8" => i4,
"144_8" => i5,
"145_8" => i6,
"151_8" => i7,
"152_8" => i8,
"158_8" => i9,
"164_8" => i10,
"165_8" => i11,
"166_8" => i12,
"167_8" => i13,
"168_8" => i14,
"169_8" => i15,
"175_8" => i16,
"176_8" => i17,
"182_8" => i18,
"183_8" => i19,
"184_8" => i20,
"190_8" => i21,
"196_8" => i22,
"197_8" => i23,
"198_8" => i24,
"199_8" => i25,
"200_8" => i26,
"214_8" => i29,
"215_8" => i30,
"216_8" => i31,
"222_8" => i32,
"223_8" => i33,
"224_8" => i34,
"225_8" => i35,
"226_8" => i36,
"227_8" => i37,
"233_8" => i38,
"234_8" => i39,
"235_8" => i40,
"236_8" => i41,
"237_8" => i42,
"243_8" => i43,
"244_8" => i44,
"245_8" => i45,
"251_8" => i46,
"252_8" => i47,
"253_8" => i48,
"254_8" => i49,
"255_8" => i50,
"256_8" => i51,
"257_8" => i52,
"263_8" => i53,
"264_8" => i54,
"265_8" => i55,
"266_8" => i56,
"267_8" => i57,
"268_8" => i58,
"269_8" => i59,
"270_8" => i60,
"271_8" => i61,
"272_8" => i62,
"278_8" => i63,
"279_8" => i64,
"280_8" => i65,
"281_8" => i66,
"282_8" => i67,
"283_8" => i68,
"289_8" => i69,
"290_8" => i70,
"296_8" => i71,
"297_8" => i72,
"298_8" => i73,
"299_8" => i74,
"300_8" => i75,
"301_8" => i76,
"307_8" => i77,
"308_8" => i78,
"309_8" => i79,
"310_8" => i80,
"311_8" => i81,
"312_8" => i82,
"313_8" => i83,
"314_8" => i84,
"315_8" => i85,
"316_8" => i86,
"317_8" => i87,
"318_8" => i88,
"324_26" => i89,
"328_37" => i90,
"332_48" => i91,
"338_59" => i92,
"344_59" => i93,
"345_59" => i94,
"351_8" => i95,
"352_8" => i96,
"353_8" => i97,
"354_8" => i98,
"364_8" => i100,
"365_8" => i101,
"366_8" => i102,
"367_8" => i103
)//comma missing
$demoFkids = Array
(
"129_2" => b1
)//comma missing
$commentFkids = Array
(
"373_375" => 1,
"380_382" => 2
)//comma missing
?>
We need to insert a file something like this
Desired Output
<?php
$itemFkids = Array
(
"203_19" => "i27",//notices the double quotes here
"207_22" => "i28",
"357_22" => "i99",
.
.
.
.
.
.
),//notice a comma here
$demoFkids = Array
(
"129_2" => "b1"//notices the double quotes here
),//notice a comma here
$commentFkids = Array
(
"373_375" => "1",
"380_382" => "2"//notices the double quotes here
),//notice a comma here
?>
Thanks for your help in advance :)
You can use something like this:
<?php
$a = array (1, 2, array ("a", "b", "c"));
var_export($a);
?>
And this outputs:
array (
0 => 1,
1 => 2,
2 =>
array (
0 => 'a',
1 => 'b',
2 => 'c',
),
)
Check out the documentation at http://php.net/manual/fr/function.var-export.php
Code for the desired output:
<?php
$result = array_merge($itemFkids, $demoFkids, $commentFkids);
var_export($result);
?>
Outputs:
<?php
$itemFkids = Array
(
"203_19" => "i27",
"207_22" => "i28",
"357_22" => "i99",
.
.
.
),
$demoFkids = Array
(
"129_2" => "b1"
),
$commentFkids = Array
(
"373_375" => "1",
"380_382" => "2"
),
?>
Cannot reliably say until we work with the full code! :)
try using the php function var_export
Even trying this is worth:
<?php
class A
{
public $var1;
public $var2;
public static function __set_state($an_array)
{
$obj = new A;
$obj->var1 = $an_array['var1'];
$obj->var2 = $an_array['var2'];
return $obj;
}
}
$a = new A;
$a->var1 = 5;
$a->var2 = 'foo';
eval('$b = ' . var_export($a, true) . ';'); // $b = A::__set_state(array(
// 'var1' => 5,
// 'var2' => 'foo',
// ));
var_dump($b);
?>
The output of the above is:
object(A)#2 (2) {
["var1"]=>
int(5)
["var2"]=>
string(3) "foo"
}