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

PHP SUBMIT
Code: <input name="doLogin" type="image" src="images/loginsubmit.jpg

Tree Menu
Hi guys,

Can anyone help me making a tree navigation system? I have a site where I'm allowin

Transform value 0 in no and 1 in yes help needed
Hello,
I have this in the table: "value" type int 0 to represent false and 1 to represe

how can i display php source code snippets ?
I am outputting some pho code .. and I want to display the source code so people can copy and paste

HTAccess auto log in?
Hi all.

Too busy driving celebs about lately so I hope someone here can help me out.

I

Help with PHP Email Script
Hi guys,

I'm a newbie to php and need help with the script below:

At the moment when I

how do i make new line after *
First check this page here. and you see my report. Im pulling form a mysql db. I want to beable to m

mySQL and PHP search
Hello,
I am trying to code a project and ran into a brick wall with one of my pages. I am pretty

Multiple submit forms inside a mysql array page
Hi all,

Im having trouble to get the beneath script to work the thing i can't seem to get wor

Basic Question about Threading and PHP...
I have a page that I am working on and it is taking several hours to process. The basics of what th

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