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

Solution Manager BPR
Does the SolMan-BPR-ARIS-Integration (http://www.ids-scheer.com/en/ARIS/ARIS_Platform/ARIS_Business_

question about stripslashes and real_escape_string
im cleaning up an old app that I wrote fixing some of the vulernabilities from attacks.

I hav

Socket problem
Hello,

Earlier I posted about my problem with my socket script. It took up to 100% CPU usage.

mail()
Hi all. I have a problem with emails. I am trying to set up a mail system where customers can subscr

Automatically Detect Phone Model for WAP Jar Deployment
Making a wap site is fairly simple, but I'd like to know if there's a way to make it so that the wap

Batch update record with Pagination
Hoping someone can help me with this issue I'm having, im trying to batch update records from a resu

Parse String
I need to parse the string below into three variables. How would I do that?

john + 10/20/2008

PHP page is blank
Hi Everyone,

I have a site in which I am able to open the first PHP webpage in my browser but

download directory onto C drive
I am attempting (if this is possible) to write a routine to automatically dump the contents of a dir

Displaying Column Names
I have a question regarding the ability to show the column names from my table/query.
What I'm lo

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