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

Getting number of affected rows in SQLPLUS..
Hi everyone,
I have a shell script where i am invoking sqlplus, running a query and saving t

Retrieving the 25 most recently added entries from all tables in a MySQL databas
Hello,

The code below works great. It creates a table that shows the 25 most recently added t

Help with PHP and checkboxes
I am posting this for a friend of mine, i wrote a small script for her to process her form data to a

CHECH A STRING FOR ' " ' (DOUBLE QUOTES)
I am checking for delimiter (.!?) and if there is a " after a sentence then it should neglect a

string to currency format
Hi guys...

Actually I chunk out some data from txtfile and one of the data contains amount va

DateObject and Nulls
Hi all,

I have an array mapped to a value object. One of the items in the array is a PHP Date

Update not working ... please help
Hi,

I am trying to update a row using an edit form by passing id of the row .. but it is not

convert static html data into dynamic
hi all

i need to convert a website which has static above 2000 articles into dynamic and add

Simpler method of getting variables from mysql
Hi Guys,

I'm trying to streamline my CMS's code and as I was writing a new page it occured to

Dynamic links in an include file
I am working on a small piece of code that counts records from a database and displays the result to

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