PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I need to add a third colur (red) which will display if the field for a row in a field reads "yes".
In this case the current table simply outputs asset information into a table and lists all of the assets. I would like it so that assets which have been decomissioned show a background colour of red. This is determined if a value = yes.
mysql_select_db("audit") or die("Problem selecting database");
$query = "SELECT * FROM dedicated order by type";
$result = mysql_query($query) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);
echo "<TABLE BORDER=\"0\" table width=\"100%\">\n";
echo "<TR bgcolor=\"#cccccc\"><TD font colour=\"red\"><b>Asset</b></TD><TD><b>Title</b></TD><TD><b>Customer</b></TD><TD><b>Type</b></TD><TD><b>IP address</b></TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
$stopped = mysql_fetch_array($result);
if($stopped =='yes'){
echo "<TR bgcolor=\"#ffcccc\">\n";
}
else if($i % 2) {
echo "<TR bgcolor=\"#ffff99\">\n";
}
else {
echo "<TR bgcolor=\"#ffffcc\">\n";
}
//now let's close the table and be done with it
echo "</TABLE>\n";
[b]$query = "SELECT * FROM dedicated order by type";
$result = mysql_query($query) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);
echo "<TABLE BORDER=\"0\" table width=\"100%\">\n";
echo "<TR bgcolor=\"#cccccc\"><TD font colour=\"red\"><b>Asset</b></TD><TD><b>Title</b></TD><TD><b>Customer</b></TD><TD><b>Type</b></TD><TD><b>IP address</b></TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
$stopped = $row['stopped'];
}
if($stopped =='yes'){
echo "<TR bgcolor=\"#ffcccc\">\n";
}
else if($i % 2) {
echo "<TR bgcolor=\"#ffff99\">\n";
}
else {
echo "<TR bgcolor=\"#ffffcc\">\n";
}
//now let's close the table and be done with it
echo "</TABLE>\n";
?>[/b]
This is simply not outputting anything. I believe its because I have closed the for loop in an incorrect space. Please could you advise.