Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP to create table columns

Status
Not open for further replies.

A1Simon

Technical User
Nov 16, 2016
1
0
0
GB
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,

Si

 
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

Code:
echo('<td '); //open td
	if ([$value] < 6){
		echo('class=\"redclassname\">');
	elseif ($value > 5 and value < 7){
		echo('class=\"amberclassname\">');
	...
	... continue conditions
	}

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

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




Chris.

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.
 
Try this
Code:
$colors=array(
    0=>'#ff0000',
    1=>'#ff0000',
    2=>'#ff0000',
    3=>'#ff0000',
    4=>'#ff0000',
    5=>'#ff0000',
    6=>'#ff9933',
    7=>'#ff9933',
    8=>'#00cc00',
    9=>'#00cc00',
    10=>'#00cc00'
    );
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>';
}


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top