Forum Moderators: coopster

Message Too Old, No Replies

order of script execution

         

bilenkyj

9:01 am on Oct 9, 2008 (gmt 0)

10+ Year Member



hi guys, i was wondering if anyone could help with this.

I have a table that is created via while loop, within the lopp is some info that is calculated and extracted from a db and used later on in the script, the issue i have is using some of this detail to change the background color of a table cell. here is the pesudo script type thingy to show ordering

while(records in db create the following){
<td>

while(another check is performed to extract and obtain more info){
within this while loop is the data i need to drive the <td bgcolor change> in the encapulating while loop.
}
}

I cannot move the <td> into the other while loop as it messes up the table structure. I am unsure how to change the td bgcolor because of the scripts order of execution. Has anyone got any ideas, i was thinking about stretching out the <td> but i do echo other things to screen inbetween the 2 points which would appear in the <td> and the while lopp would be an issue as well. is it possible to define the cells background color outside of the td tags?

andrewsmd

1:43 pm on Oct 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just use some css I'm not going to explain the css
CSS code
.tableBG1{

background-color: black;
color: white;

}
.tableBG2{

background-color: white;
color: black;

}
you can format those tags however you want
Now in your php
while(records in db create the following){
<td>

while(another check is performed to extract and obtain more info){

if(your first check){
echo("<td class = 'tableBG1'>Some output</td>");
}//if
else{
echo("<td class = 'tableBG2'>Some output</td>");
}//else

}

If you want more detailed instructions post your code and ill edit it for you

bilenkyj

2:13 pm on Oct 9, 2008 (gmt 0)

10+ Year Member



this wouldnt work as the first check doesnt contain the details required to work out what colour the background should be, if it was my original attempt would work. your solution is the same as mine but with css

bilenkyj

2:28 pm on Oct 9, 2008 (gmt 0)

10+ Year Member



is there something i can put in here

<td>something here to make colour change</td>

instead of here
<td bgcolor="green"></td>

andrewsmd

4:41 pm on Oct 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not following why that won't work, can you paste some code?

gcarn

4:50 pm on Oct 9, 2008 (gmt 0)

10+ Year Member



What you might want to do is first parse the SQL query into an array, you can then parse that array to get the information you need.

Then you can iterate through the array and make your table, just like you would with the loop from your SQL.

grallis

9:07 pm on Oct 9, 2008 (gmt 0)

10+ Year Member



If you assign unique id's to each table cell using the id's from the database, or even a counter, you can use javascript to change the cell colour:


echo "<script type=\"text/javascript\" language=\"javascript\">document.getElementById(id_here).style.backgroundColor = "yellow"</script>";

Something like that would work if the id's were assigned properly.

MattAU

9:19 pm on Oct 9, 2008 (gmt 0)

10+ Year Member



I reckon joining strings is the way to go. Lots of echo statements are bad for performance anyway.

$output = '';

while(records in db create the following){
$record = '';
$record .= 'something';

while(another check is performed to extract and obtain more info){
$record .= 'something else';
$colour = 'blue';
}
$record = "<td style='color: $colour'>$record";
$output .= $record;
}

echo $output;

Anyango

6:30 am on Oct 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



MattAU's solution seems to be your best bet, you might need some modification but basically that is worth the first try.