Reputation: 5105
I have a dropdown/sort select list with 2 options Popularity and Recently Ordered
.
I want to filter objects on the page by these attributes and I want to connect the two options in my select to respective functions in my dataloader.php file.
The functions are below but I want to connect $ofpg->reorder
to recently ordered and $ofpg->topseller
to popularity, but I'm not sure how exactly to load these to my select box and attach JS to sort by. Basically I just want to use JS to reorder the items on the page by these items, but I need some guidance to get started.
Here's the code:
My dropdown/sort by:
<div style="text-align:center;">
<div>
<span style="color:#fff;"><strong>Sort by:</strong></span>
<select class="uk-text-muted" style="margin-top:10px; width:33%; height:30px; font-size: 16px;" >
<option class="uk-text-muted" style="font-size: 16px;" value="" selected data-default>Popularity</option>
<option class="uk-text-muted" style="font-size: 16px;" value="">Recently Ordered</option>
</select>
</div>
</div>
Top seller and recent order functions:
$ofpg = new OfDataProductGroup();
$ofpg->group_code = trim($group['groupCode']);
$ofpg->group_name = $group['groupName'];
$ofpg->group_desc = $group['webDsc'];
$ofpg->ctg = $group['ctg'];
$ofpg->topseller = 0;
$ofpg->reorder = 0;
if($this->reorder){
foreach($this->reorder as $i){
if(trim($group['groupCode']) == $i->STYLE){
$ofpg->reorder = 1;
continue;
}
}
}
if($this->topsellers){
foreach($this->topsellers as $i){
$aa = json_decode($i->metadata);
$s = $aa->style[0]->prdgroup;
if(trim($group['groupCode']) == $s){
$ofpg->topseller = 1;
continue;
}
}
}
Upvotes: 2
Views: 67
Reputation: 1252
Something that might work is using an if
statement and put continue;
within it on the top of your foreach
.
Something like:
foreach($aa as $a)
{
if($a != $something) // or use ($a == $something), just whatever you need.
{
continue;
}
echo $a;
}
In the situation above you use a foreach
to do something with every key from your array. But on top of this foreach
you have an if
statement. The if
statement will only show the result if it matches the requirement, otherwise it will do nothing and continues to the next key.
EDIT:
This is written in PHP
, not in JS
.
Upvotes: 2