Solved

help with arrays in PHP.

Posted on 2012-04-02
4
292 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

726 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