Hi,
I am happy to say that with your help, I have been performing good in Ajax. Thanks for helping me to start with. I have a small problem now. I am pulling records from database and passing result of the query in a table. I would like some help with the code to colour the alternate rows please.
[PHP]
function printQuery($par am)
{
echo "<table width=100% valign=center>" ;
echo "<tr>"; foreach ($param as $key => $result)
echo "<td>";
if (is_array($resu lt))
{
printQuery($res ult);
}
else
{
echo ($result) . '<br />';
}
echo "</td>";
}
}
echo "</td>";
echo "</tr>";
echo "</table>";
[/PHP]
I tried many CSS and Javascript functions to colour table rows alternatively but they don't seem to work. No errors but wont do alternate colouring. I checked this forum also and found the following code useful but it takes the colour code from CSS for color2 CSS in every row not the first one. http://www.thescripts.com/forum/thre...ate+color.html
[PHP]
<?php
# Print the start of the table.
echo "\n<table>" ;
# Loop throught while $i is less than 10
# each time incrementing $i by one.
for($i = 0; $i < 10; $i++)
{
# $i % 2 divides the number $i by 2 and returns the rest (0 or 1)
# which I then add one to, so this will alwasy be either 1 or 2
$color = "color". ($i % 2 + 1);
# Print a row into the table.
echo "\n\t<tr><t d class=\"$color\ ">Row $i</td></tr>";
}
# Print the end of the table.
echo "\n</table>";
?>
[/PHP]
What I changed in my code was the following:
[code=CSS]
<style type="text/css">
.color1 {
background-color: white;
}
.color2 {
background-color: black;
}
</style>
[/code]
[PHP]
function printQuery($par am)
{
echo "<table width=100% valign=center>" ;
echo "<tr>";
foreach ($param as $key => $result)
{
for($i = 0; $i < 10; $i++)
{
$color = "color".($i % 2 + 1);
}
echo "<td width = 15% class=$color>";
if (is_array($resu lt))
{
printQuery($res ult); }
else { echo ($result) . '<br />'; } echo "</td>";
} }
echo "</td>"; echo "</tr>"; echo "</table>";
[/PHP]
But it can pick up the second color from my CSS and not the alternating first one. Could someone please have a look at it and let me know what is wrong in here?
I am using Ajax call so I am writing CSS code in the initial page and not in the page where PHP code is. Could this be a problem? I tried putting code in both but didnt work. I thought that is what I am supposed to do. Let me know if its incorrect.
Thank you!
I am happy to say that with your help, I have been performing good in Ajax. Thanks for helping me to start with. I have a small problem now. I am pulling records from database and passing result of the query in a table. I would like some help with the code to colour the alternate rows please.
[PHP]
function printQuery($par am)
{
echo "<table width=100% valign=center>" ;
echo "<tr>"; foreach ($param as $key => $result)
echo "<td>";
if (is_array($resu lt))
{
printQuery($res ult);
}
else
{
echo ($result) . '<br />';
}
echo "</td>";
}
}
echo "</td>";
echo "</tr>";
echo "</table>";
[/PHP]
I tried many CSS and Javascript functions to colour table rows alternatively but they don't seem to work. No errors but wont do alternate colouring. I checked this forum also and found the following code useful but it takes the colour code from CSS for color2 CSS in every row not the first one. http://www.thescripts.com/forum/thre...ate+color.html
[PHP]
<?php
# Print the start of the table.
echo "\n<table>" ;
# Loop throught while $i is less than 10
# each time incrementing $i by one.
for($i = 0; $i < 10; $i++)
{
# $i % 2 divides the number $i by 2 and returns the rest (0 or 1)
# which I then add one to, so this will alwasy be either 1 or 2
$color = "color". ($i % 2 + 1);
# Print a row into the table.
echo "\n\t<tr><t d class=\"$color\ ">Row $i</td></tr>";
}
# Print the end of the table.
echo "\n</table>";
?>
[/PHP]
What I changed in my code was the following:
[code=CSS]
<style type="text/css">
.color1 {
background-color: white;
}
.color2 {
background-color: black;
}
</style>
[/code]
[PHP]
function printQuery($par am)
{
echo "<table width=100% valign=center>" ;
echo "<tr>";
foreach ($param as $key => $result)
{
for($i = 0; $i < 10; $i++)
{
$color = "color".($i % 2 + 1);
}
echo "<td width = 15% class=$color>";
if (is_array($resu lt))
{
printQuery($res ult); }
else { echo ($result) . '<br />'; } echo "</td>";
} }
echo "</td>"; echo "</tr>"; echo "</table>";
[/PHP]
But it can pick up the second color from my CSS and not the alternating first one. Could someone please have a look at it and let me know what is wrong in here?
I am using Ajax call so I am writing CSS code in the initial page and not in the page where PHP code is. Could this be a problem? I tried putting code in both but didnt work. I thought that is what I am supposed to do. Let me know if its incorrect.
Thank you!
Comment