Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

PHP to create table columns

PHP to create table columns

PHP to create table columns

Hello, I am new to this and need some help with a little project.

In php I am looking to create a table with a certain amount of boxes / columns (like a chart) and have certain colours.

This is what I am trying to do (example):-

Product: abc123
Current Qty: 7
Target Qty: 12
Red Qty Between: >0 & <5
Amber Qty Between: >5 & <7
Green Qty Between: >7 & <10
Blue Qty Between: >10

I would like the php code to generate 12 boxes (with a small gap between each one) and each with a number
The first 5 boxes are to be filled in red
the 6th & 7th box is to be filled in amber
as the current qty is 7 then the remaining boxes are to be filled in white

As the current qty changes then the boxes will be filled in accordingly. If the current qty exceeds 10 then the boxes are to be filled in blue

Other products (about 15 in total) also need to be displayed but will each have their own values for the Current, Target, Red, Amber, Green & Blue boxes.

I hope this helps? I was looking to create a stacked barchart with a gap within each value and no axis, but thought it might be easier just to build a table.

I think this will be an easy bit of code for an experienced php developer to do but I am really struggling.

Many thanks,


RE: PHP to create table columns

Set up CSS classes for the colours and include the class attribute for the td in your display loop.

pseudo code using if .. elseif ... end construct


echo('<td '); //open td
	if ([$value] < 6){
	elseif ($value > 5 and value < 7){
	... continue conditions

echo('>$value</td>'); //print value and close td 

Or you could use a 'switch' construct for the conditions


Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.

RE: PHP to create table columns

Try this


for($x=1; $x<20; $x++) {
    $color='#FFF'; if(isset($colors[$x])) { $color=$colors[$x]; }
    echo '<div style="background-color: '.$color.'; float: left; padding: 22px; margin-left: 6px; margin-top: 12px; border: 1px solid #000; text-align: center; vertical-align: middle;">'.$x.'</div>';

The good thing about not knowing is the opportunity to learn - Yours truly, 2008.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close