$result = $proxy->salesOrderInvoiceCreate((object)array('sessionId' => $sessionId->result, 'itemsQty' => array('order_item_id' => 15, 'qty' => '1')));
$mainarray[];
$itemarray[];
I need multiple of this
array('order_item_id' => 15, 'qty' => '1')
Which means i need a array in a array.
foreach(statement){
array_push($itemarray, "order_item_id", echo $item->product_id;);
array_push($itemarray, "qty", echo $item->qty);
array_push($mainarray, $itemarray);
}
enter code here
Request Example SOAP V2 (WS-I Compliance Mode)
http://www.magentocommerce.com/api/soap/sales/salesOrderInvoice/sales_order_invoice.create.html
In fact i'm also not sure what do i replace the current
array('order_item_id' => 15, 'qty' => '1')
with
array($mainarray) ??
That is not the correct way of using array_push your current $itemarray output will look something like
Array
(
[0] => 'order_item_id'
[1] => '200'
[2] => 'qty'
[3] => '2'
)
I would go back to basics and use something like to generate your multi dimensional array:
$itemarray[] = array("order_item_id" => $item->product_id, "qty" => $item->qty);
array_push($mainarray, $itemarray);
Edit:
Ok I reread your questions, ignore $mainArray.
$result = $proxy->salesOrderInvoiceCreate((object)array('sessionId' => $sessionId->result, 'itemsQty' => $itemarray));
That should work as with the other examples qty/itemsQty show it accepting multikey arrays.
Related
I would need to combine two different fields.
In the first field I generate days of the month. I want to list all days of the month.
I would like to add a second field to them, where there are items for each day. But, for example, there are no items on weekends or on other days. Ie. that field two will always have fewer items.
The second field is tightened from the DB.
I would need to do a JOIN like in MySQL for the first field.
It occurred to me that in MySQL it would be possible to make a temporary table with a given month and link it here, but I don't think it's right.
$arrayDate = [0 => '20210401',1 => '20210402',2 => '20210403',3 => '20210404',4 => '20210405',5 => '20210406',6 => '20210407',7 => '20210408',8 => '20210409',9 => '20210410',10 => '20210411',11 => '20210412',12 => '20210413',13 => '20210414',14 => '20210415',15 => '20210416',16 => '20210417',17 => '20210418',18 => '20210419',19 => '20210420',20 => '20210421',21 => '20210422',22 => '20210423',23 => '20210424',24 => '20210425',25 => '20210426',26 => '20210427',27 => '20210428',28 => '20210429',29 => '20210430'];
$arrayItem[35] = ['id' => 35, 'date' => '20210401', 'item' => 'aaaa'];
$arrayItem[36] = ['id' => 36, 'date' => '20210402', 'item' => 'bbbb'];
$arrayItem[37] = ['id' => 36, 'date' => '20210430', 'item' => 'cccc'];
// i need output
20210401 - aaaa
20210402 - bbbb
20210403 - empty
20210404 - empty
...
20210430 - cccc
EDIT: I use nested loops, but I still can't get the right output
foreach ($arrayDate as $date) {
foreach ($arrayItem as $item) {
if ($date == $item['date']) {
bdump($item['date']);
} else {
bdump($date);
}
}
}
bdump($item['date']) = '20210401', '20210402', '20210430'
bdump($date) = '20210401', '20210401', '20210402', '20210402', '20210403', '20210403', '20210403', '20210404', '20210404', '20210404', '20210405', '20210405', '20210405' ....
With array_column you create a array from $arrayItem with date as key.
$dateItem is an array like
array (
20210401 => "aaaa",
20210402 => "bbbb",
20210430 => "cccc",
)
The output you can do with a simple foreach.
$dateItem = array_column($arrayItem,'item','date');
foreach($arrayDate as $date){
echo $date.' '.($dateItem[$date] ?? 'empty')."<br>\n";
}
Note:
With
array_column($arrayItem,null,'date')
you get a two-dimensional array with a date as a key that can be used.
array (
20210401 =>
array (
'id' => 35,
'date' => "20210401",
'item' => "aaaa",
),
20210402 =>
array (
'id' => 36,
'date' => "20210402",
'item' => "bbbb",
),
20210430 =>
array (
'id' => 36,
'date' => "20210430",
'item' => "cccc",
),
)
I wrote a program to define an associative array titled $aFilter and tried to print it but I'm not able to. I tried two ways to achieve this but couldn't succeed. Following are the two ways I tried.
Way 1:
<!DOCTYPE html>
<html>
<body>
<?php
$aFilter = Array
(
['pages'] => 1,
['photo'] => 1,
['link'] => 1,
['event'] => 1,
['friend'] => 1,
['user_status'] => 1,
['poll'] => 1,
['quiz'] => 1,
['market'] => 1,
['apps'] => 1
)
print_r($aFilter);
?>
</body>
</html>
Way 2:
<!DOCTYPE html>
<html>
<body>
<?php
$aFilter = Array
(
['pages'] => 1
['photo'] => 1
['link'] => 1
['event'] => 1
['friend'] => 1
['user_status'] => 1
['poll'] => 1
['quiz'] => 1
['market'] => 1
['apps'] => 1
)
print_r($aFilter);
?>
</body>
</html>
After executing both of the above codes I'm getting blank white screen. No any error or warning. Why so happens? How can I get errors and warnings displayed on my webpage without making any change to php.ini file settings?
Can someone please correct the mistake I'm making and help me?
You forgot an ; after defining the array.
And also don't use [] when defining an array. More info on array's.
$aFilter = Array(
'pages' => 1,
'photo' => 1,
'link' => 1,
'event' => 1,
'friend' => 1,
'user_status' => 1,
'poll' => 1,
'quiz' => 1,
'market' => 1,
'apps' => 1
);
print_r($aFilter);
print_r() displays information about a variable in a way that's readable by humans.
It is not the code you need to write.
Both ways are missing the ; after the array definition and Way 2 is missing ,s after each array element. Also, both ways should use 'elName' => 'elValue', instead of ['elName'] => 'elValue',
The problem are:-
Forgot an ; after defining the array.
When you hard-coded value you need to put indexes without brackets.
So write in this way:-
$aFilter = Array(
'pages' => 1,
'photo' => 1,
'link' => 1,
'event' => 1,
'friend' => 1,
'user_status' => 1,
'poll' => 1,
'quiz' => 1,
'market' => 1,
'apps' => 1
);
print_r($aFilter);
i have this array in an example, how can i get the same result from query from database?, i need to replace the values which the values of the database.
$data = array(
array(
'qty' => 1,
'Price' => 1.00,
'total' => 1.00
),
array(
'qty' => 2,
'Price' => 1.00,
'total' => 2.00
),
array(
'qty' => 3,
'Price' => 1.00,
'total' => 3.00
)
);
then in the example use the nusoap lib
foreach($data as $concept) {
$par['Concepts'][] = new soapval('Concept', 'Concept', $concept);
}
so i need to call the query:
$query_data_cot = mysql_query("SELECT * FROM data WHERE id='1'");
while($data_quote=mysql_fetch_array($query_data_cot)){
$conceptosDatos[]["qty"]=$data_quote['qty'];
$conceptosDatos[]["Price"]=$data_quote['price'];
$conceptosDatos[]["total"]=$data_quote['total'];
}
but when i do these i got an error
Error: Array ( [faultcode] => soap:Server [faultstring] => Server was unable to process request. --->
thank you
Everytime you use $conceptosDatos[]... the [] will create a new subarray. So your result will be something like this
array(
array('qty' => ..),
array('Price' => ..),
array('total' => ...),
array('qty' => ..),
array('Price' => ..),
array('total' => ...),
...
)
Instead you need to create a new subarray only for a whole set, so use something like this
$query_data_cot = mysql_query("SELECT qty, price, total FROM data WHERE id='1'");
while($data_quote=mysql_fetch_assoc($query_data_cot)){
$conceptosDatos[] = $data_quote;
}
Of course you could also do it like this
$query_data_cot = mysql_query("SELECT qty, price, total FROM data WHERE id='1'");
while($data_quote=mysql_fetch_assoc($query_data_cot)){
$conceptosDatos[] = array(
'qty' => $data_quote['qty'],
'Price' => $data_quote['price'],
'total' => $data_quote['total'],
);
}
But why write every field if you're going to copy the whole array anyway?
If you need to use different names (as in your example price and Price), you can either change your db schema or use aliases in your query, giving you this code:
$query_data_cot = mysql_query("SELECT qty, price AS Price, total FROM data WHERE id='1'");
while($data_quote=mysql_fetch_assoc($query_data_cot)){
$conceptosDatos[] = $data_quote;
}
This has the advantage that if you wish to modify your code in the future, you'd only need to modify the query (and could probably encapsulate this logic inside a function) - so less work for future you.
By the way, did you see the big red box in the manual on all mysql_* methods's sites? It's deprecated and PDO as well as MySQLi are way better alternatives. This helps decide what to use.
Try this , while($data_quote=mysql_fetch_array($query_data_cot , MYSQL_ASSOC )) , as you are retrieving the $data as an associative array .
Each assignment line in your loop is creating a new element of the $conceptDatos array, not filling in a different element of the same element. So your array looks like:
array(
array('qty' => 1),
array('Price' => 1.0),
array('total' => 1.0),
array('qty' => 2),
array('Price' => 1.0),
array('total' => 1.0),
...
)
Your loop shoud be:
while($data_quote=mysql_fetch_array($query_data_cot)){
$conceptDatos[] = array(
'qty' => $data_quote['qty'],
'Price' => $data_quote['price'],
'total' => $data_quote['total']
);
}
I'm trying to grab data from this array, but when I do var_dump($ArrayedLevels['Attack']); it returns NULL, I know for a fact that it was able to grab the data from the SQL database, I think it has something to do with my array. Any help would be greatly appreciated.
include("highscoresconfig.php");
$GrabXP = $database2->prepare("SELECT * FROM `skills` WHERE `playerName` = ?");
$GrabXP->execute(array($playerName));
$MainResult = $GrabXP->fetchAll();
$ArrayedLevels = $array = [
"Attack" => $MainResult['Attacklvl'],
"Defence" => $MainResult['Defencelvl'],
"Strength" => $MainResult['Strengthlvl'],
"Hitpoints" => $MainResult['Hitpointslvl'],
"Ranged" => $MainResult['Rangelvl'],
"Prayer" => $MainResult['Prayerlvl'],
"Magic" => $MainResult['Magiclvl'],
"Cooking" => $MainResult['Cookinglvl'],
"Woodcutting" => $MainResult['Woodcuttinglvl'],
"Fletching" => $MainResult['Fletchinglvl'],
"Fishing" => $MainResult['Fishinglvl'],
"Firemaking" => $MainResult['Firemakinglvl'],
"Crafting" => $MainResult['Craftinglvl'],
"Smithing" => $MainResult['Smithinglvl'],
"Mining" => $MainResult['Mininglvl'],
"Herblore" => $MainResult['Herblorelvl'],
"Agility" => $MainResult['Agilitylvl'],
"Thieving" => $MainResult['Thievinglvl'],
"Slayer" => $MainResult['Slayerlvl'],
"Farming" => $MainResult['Farminglvl'],
"Runecrafting" => $MainResult['Runecraftlvl'],
"Hunter" => $MainResult['Hunterlvl'],
"Construction" => $MainResult['Constructionlvl'],
"Summoning" => $MainResult['Summoninglvl'],
"Dungeoneering" => $MainResult['Dungeoneeringlvl'],
];
var_dump($ArrayedLevels["Attack"]);
Problem might be because the fetchAll() returns all the rows of your query.
if($GrabXP->execute(array($playerName))){
//Success
$MainResult = $GrabXP->fetchAll();
/*
This will give you all the rows. Use a foreach loop to iterate through all the rows.
If you want only the first row, add this-
*/
$MainResult = $MainResult[0];
//The rest of your code.
$ArrayedLevels = $array = Array(
"Attack" => $MainResult['Attacklvl'],
...
);
var_dump($ArrayedLevels["Attack"]);
}
else{
//Failure
}
The brackets don't work in PHP when creating a new array, use array() to create one.
Actually: as of PHP 5.4 they do work, see here: http://nl3.php.net/manual/en/language.types.array.php
Try var_dump($MainResult);
if all good, try create your array like this:
$ArrayedLevels = array(
"Attack" => $MainResult['Attacklvl'],
"Defence" => $MainResult['Defencelvl'],
"Strength" => $MainResult['Strengthlvl'],
"Hitpoints" => $MainResult['Hitpointslvl'],
"Ranged" => $MainResult['Rangelvl'],
"Prayer" => $MainResult['Prayerlvl'],
"Magic" => $MainResult['Magiclvl'],
"Cooking" => $MainResult['Cookinglvl'],
"Woodcutting" => $MainResult['Woodcuttinglvl'],
"Fletching" => $MainResult['Fletchinglvl'],
"Fishing" => $MainResult['Fishinglvl'],
"Firemaking" => $MainResult['Firemakinglvl'],
"Crafting" => $MainResult['Craftinglvl'],
"Smithing" => $MainResult['Smithinglvl'],
"Mining" => $MainResult['Mininglvl'],
"Herblore" => $MainResult['Herblorelvl'],
"Agility" => $MainResult['Agilitylvl'],
"Thieving" => $MainResult['Thievinglvl'],
"Slayer" => $MainResult['Slayerlvl'],
"Farming" => $MainResult['Farminglvl'],
"Runecrafting" => $MainResult['Runecraftlvl'],
"Hunter" => $MainResult['Hunterlvl'],
"Construction" => $MainResult['Constructionlvl'],
"Summoning" => $MainResult['Summoninglvl'],
"Dungeoneering" => $MainResult['Dungeoneeringlvl'],
);
first of all try to print the structure of the variable $MainResult:
var_dump($MainResult);
FetchAll return an array with all restuls like
resutl = [
[0] => ['first row'],
[1] => ['sec. row']
]
you will See The variable $MainResult looks like:
MailResult => [
[0] => ['Attacklvl' => 'foo'],
[1] => ['Defencelvl' => 'bar']
]
Originaly posted on cakephp Q&A but i'll put it up here in hope of getting some answers.
I have a bunch of companies that has a status of 0 as default but sometimes get a higher status. Now i want to use the high status if exists but revert to 0 if not. i have tried a bunch of different approaches but i always get either only the ones with status 0 or the ones with the status i want, never giving me status if exists and 0 if not.
Gives me only the status i specify, not giving me the ones with status 0:
'Company' => array (
'conditions' => array (
'OR' => array(
'Company.status' => 0,
'Company.status' => $status,
)
)
)
Gives me only status of 0:
'Company' => array (
'conditions' => array (
'OR' => array(
'Company.status' => $status,
'Company.status' => 0
)
)
)
Status definition and retrieving data in code:
function getCountry($id = null, $status = null) {
// Bunch of code for retrieving country with $id and all it's companies etc, all with status 0.
$status_less_companies = $this->Country->find...
if ($status) {
$status_companies = $this->Country->find('first', array(
'conditions' => array(
'Country.id' => $id
),
'contain' => array(
'Product' => array (
'Company' => array (
'conditions' => array (
'OR' => array(
'Company.status' => $status,
'Company.status' => 0
)
)
)
)
)
)
}
// Mergin $status_less_companies and $status_companies and returning data to flex application.
}
I changed the name for the models for this question just to make more sense, people are generaly frighten away when i tell them i work with cakephp for my flex application. I guess the logic to this question doesn't make sense but trust me that it makes sense in my application.
Thanks!
Try
'Company' => array (
'conditions' => array (
'OR' => array(
array('Company.status' => 0),
array('Company.status' => $status),
)
)
)
In the cookbook it says to wrap the or conditions in arrays if they are pertaining to the same field
http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#complex-find-conditions
I'm not sure to have understood what results you expect. If you want to retrieve all records having status = 0, plus let's say the one having status = 3, you could use an 'IN' instead of an 'OR'.
In Cake, you would write it like this:
$status = 3;
$conditions = array('Company.status' => array(0, $status));
You can also fetch record by using following method:
put values in an array
e.g. $arr=array(1,2);
$res = $this->Model->find('all', array(
'conditions' =>array('Model.filedname'=>$arr),
'model.id' => 'desc'
));
I hope you will find answer.
$this->loadModel('Color');
$colors = $this->Color->find('all', [
'conditions' => [
'Color.is_blocked' => 0,
'Color.is_deleted' => 0,
'OR' => [
[
'Color.isAdmin' => $user_data['id'],
],
[
'Color.isAdmin' => 0,
]
],
]
]);