grouping within a foreach?


Posted on 16th Feb 2014 07:03 pm by admin

hello all,

I currently have a list of products spit out from my db via a foreach loop. Right now I am styling these as a <li>

Did you know?Explore Trending and Topic pages for more stories like this.
I want to style the list so that the annual and the monthly products are grouped together. This will probably mean using <div> instead of <li> and placing another loop inside the foreach to grab two products and put them in one div?

Any ideas how this might be structured??

should I use a for loop?

here is the current code:
Code: $productnames = '<center><table><tr><td><ul id="prodlist">'."n"; // list of products that can view this content
$show2all = false; // are one of the products the "all" flag?
$numcanview = 0; // the number of products that can view this post

foreach ($_product_id as $pid)
{

$pid = trim(strtolower($pid)); // make sure no extra spaces and not "ALL" or something

if ($pid=="all")
{

$show2all = true; // used later

} else {

$purl = $this->amprotectamroot.'member.php?price_group='.$allthepricegroups[$pid].'&product_id='.$pid;

$productnames .= '<li><a href="'.$purl.'">'.$alltheproducts[$pid].'</a></li>'."n";

$numcanview++;

}
No comments posted yet

Your Answer:

Login to answer
103 Like 48 Dislike
Previous forums Next forums
Other forums

strptime() equivalent for php4 ?!
Greetings!

this is my first post, thank you in advance for your replies.

Well, the ti

have trouble in a if condition
The if below is working ok, it check when indexes, name, zipcode and state are empty.
Code: &

insert/update functions for mysql, what do you think?
I am working on two really simple functions that automatically generate (and execute) insert and upd

Curly Bracket Delimeters.
I'd always believed that the starting and ending delimeters in preg_ functions had to be the same ch

Multi Dimensional Array Append
Hi Guys

I have a function that returns a multidimentional array eg

$result = functio

Problem with an browser game.
Hello,i just joined that great forum and i got php prob,its kinda freaky...anyway i got browser game

Results from Db outputted twice
Hey guys.. for come reason my data is outputted twise shown in the image below and i cant figure out

Having a problem get the selected item from a drop down menu
I have been looking at this for days now.

I have a drop down menu that get it's values from a

Inserting into MySQL Newbie
Hi ive got a slight problem where ive made a simple web form where the customer inserts the ammount

Get dump of MySQL DB from Live Site
I'm after an easy, but secure way of generating and importing a MySQL dump from a remote server.

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash