Solved

help with arrays in PHP.

Posted on 2012-04-02
4
291 Views
Last Modified: 2012-04-03
Hi, I need some help with how to write a script for an array. I have a table with 7 rows and 5 columns ( this may vary ). The cells are named in the following way:

11 12 12 14 15 16 17
21 22 23 24 25 26 27
....
....

I need to color certain cells ( with the same color ); I know the starting cell and the ending cell, for eg the first cell could be 14 and the last cell could be 27. I need to shade all cells starting from 14 to 27 ( 11 cells ) . How do I do this? Thanks for the help.

A
0
Comment
Question by:aej1973
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 175 total points
ID: 37798533
You actually don't need arrays for this.
The following code does the trick:
<?php
// Color any table cells
$first = 14;    // first cell to color
$last  = 27;    // last cell to color

$cols  = 7;     // Number of columns in the table
$lines = 5;     // Number of lines in the table

$color  = "white";  // default cell color
$output = "<table>\n";
// iterate through each line
for($l=1; $l<$lines; $l++){
    $output.= "<tr>\n";
    // iterate through each column
    for($c=1; $c<$cols; $c++){
    	// determine this cell number
    	$cellnumber = $l*10+$c;
    	// determine this cell color
    	if($cellnumber >= $first && $cellnumber <= $last){
    		$color = "blue";    // defined range's cell color
    	}else{
    		$color  = "white";  // default cell color
    	}
        $output.= "<td style=\"background-color:$color;\" name=\"$cellnumber\">$cellnumber\n</td>\n";
    }
    $output.= "</tr>\n";
}
$output.= "</table>\n";

// output the table's HTML
echo $output;
?>

Open in new window

0
 

Author Comment

by:aej1973
ID: 37798539
Thanks  let me try it...
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37798942
I need to color certain cells ( with the same color )
How do you know what cells are to have what colors?  How is this matrix created?  Is it a PHP two-dimensional array or a table of HTML rows and columns?  Please give us a little more to go on, thanks.
0
 

Author Closing Comment

by:aej1973
ID: 37802983
Thank you works great!
0

Featured Post

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question