EAV_Databasesystem in Magento 1.6 - magento

I have a strange problem with Magentos EAV-Databasesystem.I want to store a dataset like the next codeblock. But one value 'StoreId' was not stored. Do you have any Idea why one of eight values can stored in a table.
public function populateEntriesAction()
{
//return;
for ( $i = 0; $i < 5; $i++ )
{
$branchEntry = Mage::getModel('branch/eavisbranch');
$branchEntry->setName('abc ' . $i);
$branchEntry->setStreet('abcdefg ' . $i);
.....
$branchEntry->setStorePickup(false);
$branchEntry->setStoreId('3');
$branchEntry->save();
}
echo 'Done';
}

Related

explode comma from an array value in codeigniter

I want to explode coma from an array value.
My code is.
$to_ids_string = "";
$to_id = $this->input->post('to');
for ($r = 0; $r < count($this->input->post('to')); $r++) {
if ($to_ids_string != "") {
$to_ids_string = $to_ids_string . "," . $to_id[$r];
} else {
$to_ids_string = $to_id[$r];
}
}
echo $to_ids_string;
$a = explode(',', $to_ids_string);
foreach ($a as $item) {
echo("<li>$item</li>");
exit;
}
when i echo $to_ids_string it will return 2,3 but when i loop in foreach it only return 2 not show 3.
Because of your exit, if you use exit like that, then it is the end of your program and it doesn't echo anymore.
You forget to remove exit; from foreach loop. When you write exit, execution of your code stops. Hence you are not getting desired output.
Happens due to exit.
Please remove exit from your code.

Laravel Blade - loop for

How can i do it:
#for ($i = 1; $i < 11; $i++)
#if ($categorie->t$i != null)
{{$categorie->t$i}}
#endif
#endfor
categorie->t$i = categorie->t1 , t2, t3 ... t10.
Thanks !
You can access the item t$i by concatinating the string 't' with the value of $i, and afterwards accessing this.
First:
$item_name = 't' . $i;
Then:
$category->$item_name
This should do the trick.

Alogrithm in using perl to find the value in array - Absolutely Interview Questions

I am asked to do the perl program to find a value(from user input) in array. If matched "its ok". If not matched, then check within the value in the index[0] to index[1] ... index[n]. So then if the value matched to the between two elements then report which is near to these elements might be index[0] or index[1].
Let you explain.
Given array : 10 15 20 25 30;
Get the value from user : 14 (eg.)
Hence 14 matched with in the two elements that is 10(array[0]) - 15(array[1])
Ultimately the check point is do not use more than one for loop and never use the while loop. You need to check one for loop and many of if conditions.
I got the output by which I did here is:
use strict;
use warnings;
my #arr1 = qw(10 15 20 25 30);
my $in = <STDIN>;
chomp($in);
if(grep /$in/, #arr1)
{ } #print "S: $in\n"; }
else
{
for(my $i=0; $i<scalar(#arr1); $i++)
{
my $j = $i + 1;
if($in > $arr1[$i] && $in < $arr1[$j])
{
#print "SN: $arr1[$i]\t$arr1[$j]\n";
my ($inc, $dec) = "0";
my $chk1 = $arr1[$i] + 1;
AGAIN1:
if($in == $chk1)
{ }
else
{ $chk1++; $inc++; goto AGAIN1; }
my $chk2 = $arr1[$j] - 1;
AGAIN2:
if($in == $chk2){ }
else
{ $chk2--; $dec++; goto AGAIN2; }
if($inc > $dec)
{ print "Matched value nearest to $arr1[$j]\n"; }
elsif($inc < $dec)
{ print "Matched value nearest to $arr1[$i]\n"; }
}
}
}
However my question is there a way in algorithm?. Hence if someone can help on this one and it would be appreciated.
Thanks in advance.
You seem determined to make this as complicated as possible :-)
Your specification isn't completely clear, but I think this does what you want:
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
my #array = qw[10 15 20 25 30];
chomp(my $in = <STDIN>);
if ($in < $array[0]) {
say "$in is less than first element in the array";
exit;
}
if ($in > $array[-1]) {
say "$in is greater than last element in the array";
exit;
}
for (0 .. $#array) {
if ($in == $array[$_]) {
say "$in is in the array";
exit;
}
if ($in < $array[$_]) {
if ($in - $array[$_ - 1] < $array[$_] - $in) {
say "$in is closest to $array[$_ - 1]";
} else {
say "$in is closest to $array[$_]";
}
exit;
}
}
say "Shouldn't get here!";
Using the helper functions any and reduce from the core module List::Util and the built in abs.
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw/reduce any/;
my #arr1 = qw(10 15 20 25 30);
chomp(my $in = <STDIN>);
if (any {$in == $_} #arr1) {
print "$in is in the array\n";
}
else {
my $i = reduce { abs($in - $arr1[$a]) > abs($in - $arr1[$b]) ? $b : $a} 0 .. $#arr1;
print "$in is closest to $arr1[$i]\n";
}

Update query for loop is not working

I have a query like this inside for loop in codeigniter. But it executes with another values. Not with the values getting through POST method
$j = $_POST['hidden'];
$inv_id = $_POST['invoice_id'];
$sum = '';
for($i = 1; $i <= $j; $i++){
$wh_quantity1 = $_POST['quantity'.$i];
//print_r($wh_quantity1);
if($wh_quantity1 ==''){
$wh_quantity = 0;
}
else{
$wh_quantity = $wh_quantity1;
}
$query = "UPDATE tb_warehouse_stocks SET wh_product_qty = wh_product_qty - $wh_quantity WHERE invoice_id = '$inv_id'";
$this->db->query($query);
$sum += $wh_quantity;
}
Why it is like that. It always updates with greater values than POST value
Put this in .htaccess file
RewriteEngine On
RewriteRule ^ http://example.com/international/university-english-access-course$ http://example.com/website/page/english-access [R=301,L]
Try this in case your dont have all post index
$j = $this->input->post('hidden');
$inv_id = $this->input->post('invoice_id');
$sum = 0;
for ($i = 1; $i <= $j; $i++) {
$wh_quantity = (int) $this->input->post('quantity' . $i);
$sum += $wh_quantity;
}
$query = "UPDATE tb_warehouse_stocks SET wh_product_qty = wh_product_qty - $sum WHERE invoice_id = '$inv_id'";
$this->db->query($query);

Choosing unique set representing number puzzle

Following is the input set given.
1009 2000
1009 2001
1002 2002
1003 2002
Each line represents one group, Number represents ID of the member in the group. Problem is to choose minimum number of people which re-presents complete given set. Only one member should be choose from each Group. 2-tuple members will not repeated. But members can be part of more than one group.
So in this example answer be 1009 and 2002 which represents the sets. 1009 is chosen because it is representing two team and same is the case for 2002.
I am looking for what algorithm can be used to solve this problem.
Another example:
1009 2000
1009 2001
1002 2002
1003 2002
1004 2003
Answer can be { 1009 , 2002, 1004} or { 1009, 2002, 2003}
Actually, the example given by Sodved shows, that I was wrong. It is not solved by the edge cover, as that still leaves the problem of selecting the actual vertices.
You left some details out, so I'm making the following assumptions. Let me know if they're wrong.
There are exactly two numbers per line
No number that appears first on some line also appears second on some other line
So if you think of each number as a vertex in a graph, and each line of input as an edge between two vertices, what you've got is a bipartite graph--a set of "first numbers" and a set of "second numbers," and edges between them. Now, break up the graph into each of its connected components. In each connected component, you either have to pick all the "first numbers" or all the "second numbers." So for each connected component, pick whichever of those two options is a smaller set.
If anyone's intersted, here's some clumsy inefficent perl code which seems to solev the problem. Takes a LONG... time with a large data set. I'm sure things could be done better, especially he generation of the index permutations (sequences).
#!/usr/bin/perl
# http://stackoverflow.com/questions/6689147/
use strict;
use warnings;
# Return array of arrays with every possible sequence of 0..n-1
sub sequences($);
sub sequences($)
{
my $n = $_[0];
my #ret;
if( $n > 0 )
{
for( my $i=0; $i<$n; $i++ )
{
my #a = sequences( $n-1 );
foreach my $br (#a)
{
my #b = #$br;
splice( #b, $i, 0, $n-1 );
push( #ret, \#b );
}
}
}
else
{
#ret = ( [] );
}
return #ret;
} # END sequences
# Remove elements from set which are covered by later elements in set
sub stripset($$)
{
my( $data, $set ) = #_;
my $strip = 0;
my %cover;
for( my $i=0; $i<scalar(#$set); $i++ )
{
my $covered;
for( my $j=scalar(#$set)-1; $j>$i; $j-- )
{
if( $data->{$set->[$j]}->{$set->[$i]}
&& !$cover{$set->[$i]} )
{
$covered = 1;
$cover{$set->[$j]} = 1;
last;
}
}
if( $covered )
{
$strip = $i+1;
}
else
{
last;
}
}
if( $strip )
{
splice( #$set, 0, $strip );
}
} # END stripset
# Load input
my %links;
while( my $line = <STDIN> )
{
if( $line =~ /^\s*(\S+)\s+(\S+)\s*$/ )
{
$links{$1}->{$2} = 1;
$links{$2}->{$1} = 1;
}
else
{
warn "INVALID INPUT LINE: $line";
}
}
my #elems = keys(%links);
my #minset = #elems;
foreach my $seq ( sequences( scalar(#elems) ) )
{
my #set = map( $elems[$_], #$seq );
#print "TEST set: " . join( ' ', #set ) . "\n";
stripset( \%links, \#set );
#print "STRP set: " . join( ' ', #set ) . "\n";
if( scalar(#set) < scalar(#minset) )
{
#minset = #set;
}
}
print "Shortest set: " . join( ' ', #minset ) . "\n";
Just want to notice that this requirement
Only one member should be choose from each Group.
doesn't make much sense. If you enforce it, this simple problem
1 2
2 3
3 1
has no solutions.

Resources