Welcome to WebmasterWorld Guest from 34.229.126.29

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

order of script execution

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

Junior Member

10+ Year Member

joined:Sept 18, 2004
posts:61
votes: 0


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?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


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

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

Junior Member

10+ Year Member

joined:Sept 18, 2004
posts:61
votes: 0


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
2:28 pm on Oct 9, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 18, 2004
posts:61
votes: 0


is there something i can put in here

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

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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


I'm not following why that won't work, can you paste some code?
4:50 pm on Oct 9, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 8, 2008
posts:44
votes: 0


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.

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

Junior Member

10+ Year Member

joined:Sept 29, 2008
posts: 52
votes: 0


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.

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

Junior Member

10+ Year Member

joined:June 6, 2005
posts:109
votes: 0


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;

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 24, 2005
posts:697
votes: 0


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members