[PHP-DB] Changing colors in table?

2002-09-30 Thread Blue Tiger

Okay.
Disclaimer: I am very much the newbie, so please bear with me.

I have a piece of code that displays an array from a MySQL table. One
field in the table is blank (and is displayed as an empty column of
cells) at the moment. I want to have the blank cells display an image,
value, or change its background color based on whether the numerical
values in the previous 4 fields meet certain criteria or not. Make
sense? Maybe?

An example of what I want to show:
If table 2 has a value that is less than 5, then the last cell displayed
changes color to reflect that.
If table 2 has a value that is between 5 and 10, then the last cell
displayed changes color to reflect that as well.

Please help if you canmany thanks in advance. (I can show my code
thus far as well if that helps..)

Thanks, 
Ryan


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Changing colors in table?

2002-09-30 Thread Blue Tiger

The blank table column comes from a blank MySQL database field...(I was
initially going to blob images from there to show status change). If you
know of a way to eliminate the database field and still show the status
of the values in a web table, please point me in the right direction. I
am one of those people who have to look up everything for JavaScript.
(My main scripting beast was/is ASP...this PHP is a new project for a
company on a Solaris platform!)

-Original Message-
From: Tony S. Wu [mailto:[EMAIL PROTECTED]] 
Sent: Monday, September 30, 2002 8:04 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Changing colors in table?

I don't see where you put your blank table column.
I am guessing it might be somewhere within this for loop:

for ($i=0; $i  $num_tables; $i++) {
echo(centerh3 $arr_tablenames[$i] /h3/center);
echo('table align=center border=1tr');
$result = mysql_db_query($dbname, select * from
$arr_tablenames[$i], $id_link);
for ($ii=0; $ii  $arr_num_fields[$i]; $ii++) {
echo(th);
echo $hash_field_names[$i][$ii];
echo(/th);
} 
echo(/trtr);
$number_of_rows = @mysql_num_rows($result);
for ($iii = 0; $iii  $number_of_rows; $iii++) {
$record = @mysql_fetch_row($result);
for ($ii=0; $ii  $arr_num_fields[$i]; $ii++) {
echo(td);
echo $record[$ii];
echo(/td);
} 
echo(/tr);
} 
echo(/table);
}

If that's the case, all you need to do is, let's pretend $table_value
holds
the table value you need to determine the background color:

echo td;

if ($table_value  5)
{
echo  bgcolor = \#99\;  // whatever color you want
}
else if ($table_value = 5  $table_value  10)
{
echo  bgcolor = \#88\;  // another color
}
else// if no value matched
{
echo ;   // close td tag
}

Tony S. Wu
[EMAIL PROTECTED]

Nope, this world ain't perfect. But at least I know it's not because of
me.



Blue Tiger at [EMAIL PROTECTED] wrote:

 Can I force it to display the data sorted by the primary key?
 
 Here's the code: 
   // store table names in an array
   $arr_tablenames[] = '';

   // store number of fields per table(index 0,1,2..) in an array
   $arr_num_fields[] = '';
   for ($i=0; $i  $num_tables; $i++) {
   $arr_tablenames[$i] = mysql_tablename($tables, $i);
   $arr_num_fields[$i] = mysql_num_fields(mysql_db_query($dbname,
 select * from $arr_tablenames[$i], $id_link));
   } 

   // store field names in a multidimensional array:
   // [i] == table number, [ii] == field number for that table
   for ($i=0; $i  $num_tables; $i++) {
   for ($ii=0; $ii  $arr_num_fields[$i]; $ii++) {
   $result = mysql_db_query($dbname, select * from
 $arr_tablenames[$i], $id_link);
   $hash_field_names[$i][$ii] = mysql_field_name($result, $ii);
 
   } 
   } 

   for ($i=0; $i  $num_tables; $i++) {
   echo(centerh3 $arr_tablenames[$i] /h3/center);
   echo('table align=center border=1tr');
   $result = mysql_db_query($dbname, select * from
 $arr_tablenames[$i], $id_link);
   for ($ii=0; $ii  $arr_num_fields[$i]; $ii++) {
   echo(th);
   echo $hash_field_names[$i][$ii];
   echo(/th);
   } 
   echo(/trtr);
   $number_of_rows = @mysql_num_rows($result);
   for ($iii = 0; $iii  $number_of_rows; $iii++) {
   $record = @mysql_fetch_row($result);
   for ($ii=0; $ii  $arr_num_fields[$i]; $ii++) {
   echo(td);
   echo $record[$ii];
   echo(/td);
   } 
   echo(/tr);
   } 
   echo(/table);
   }
 
 Is that too much to sort through???
 
 -Original Message-
 From: Tony S. Wu [mailto:[EMAIL PROTECTED]]
 Sent: Monday, September 30, 2002 7:31 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP-DB] Changing colors in table?
 
 If the table's background color will be set when the page is first
 loaded,
 you can just use the bgcolor attribute of td tag.
 If you want to dynamically change the background color, you'll need to
 combine your page with javascript.
 
 Tony S. Wu
 [EMAIL PROTECTED]
 
 Nope, this world ain't perfect. But at least I know it's not because
of
 me.
 
 Blue Tiger at [EMAIL PROTECTED] wrote:
 
 Okay.
 Disclaimer: I am very much the newbie, so please bear with me.
 
 I have a piece of code that displays an array from a MySQL table. One
 field in the table is blank (and is displayed as an empty column of
 cells) at the moment. I want to have the blank cells display an
image,
 value, or change its background color based on whether the numerical
 values in the previous 4 fields meet certain criteria or not. Make
 sense? Maybe?
 
 An example of what I want to show:
 If table 2 has a value that is less than 5, then the last cell
 displayed
 changes color to reflect that.
 If table 2 has a value that is between 5 and 10, then the last cell

Re: [PHP-DB] Changing colors in table?

2002-09-30 Thread boclair


- Original Message -
From: Blue Tiger [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, October 01, 2002 10:13 AM
Subject: RE: [PHP-DB] Changing colors in table?


: The blank table column comes from a blank MySQL database field...(I was
: initially going to blob images from there to show status change). If you
: know of a way to eliminate the database field and still show the status
: of the values in a web table, please point me in the right direction.

:  I have a piece of code that displays an array from a MySQL table. One
:  field in the table is blank (and is displayed as an empty column of
:  cells) at the moment. I want to have the blank cells display an
: image,
:  value, or change its background color based on whether the numerical
:  values in the previous 4 fields meet certain criteria or not. Make
:  sense? Maybe?
: 
:  An example of what I want to show:
:  If table 2 has a value that is less than 5, then the last cell
:  displayed
:  changes color to reflect that.
:  If table 2 has a value that is between 5 and 10, then the last cell
:  displayed changes color to reflect that as well.

Ryan,

I understand you want to display the results of a db query in an html
table.  Maybe I misunderstand but it seems that this shouldn't be done by
fiddling with the database table;  fiddle with the html table instead

open mysql server
do select $result
start while loop on mysql-fetch-array($result) {
set
$summedfields = (sum field values);

if ($summedfields  == 2) {
$bgclr=red;
}
else {
$bgclr=blue;
}

if ($blankfield == NULL) {
 $blankfield = img src='image.gif' etc;
}

iterate on table row
use $blankfield and $bgclr as values the html table data cells

eoe

Louise


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php