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>

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

file_put_contents and createimagefromjpeg
All,
I do somethings and then I have the following code:
file_put_contents('./test/'.$filename

Select question
Hi,

First I would like to say that php is pretty new for me..
so please don't shoot me if

Applet JTextField Size Problem
Hello,

I recently started making an applet to calculate certain values for airplanes. However

Code Review - SQL and Insertion Attacks (Warning: Not for Newbs)
Hey guys,

Its been a while, I know. Use to love coming here to answer peoples questions, but

Chat Box in PHP
I was thinking in doing a Chat Box in PHP. For that I would use a form with two fields, Nick and Mes

How do i use vars in an array
Hiya peeps!

How do I use a var in an array. You will see $id but it isnt working.


New to PHP and just trying to understand a little code.
I hope I'm not annoying anyone or breaking the rules but I was wondering about this bit of code righ

Blogging s/w
heya frndz!!! i want to start a blog.... m looking for a s/w like oscommerce which is thr for e-comm

Sufficient protection from bad input?
I am writing a simple script to let people upload 'pages' of their own content, be it simply a few b

Array to string conversion
Can anyone help me with this?

Notice: Array to string conversion in /home/..../index.php on l

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