0

我是 PHP 新手,并试图学习足够的知识来完成一些基本功能。我已经能够为我的用户创建一个表格来编辑自己并重新显示,但我遇到了一个问题。使用下面的脚本,用户可以输入他们对各种产品的技能水平。我希望能够突出显示他们输入“0”或空白的每个单元格。用户的输入将介于 0-5 之间(如果尚未填写,则为空白)。

这一切都是在我的本地主机上完成的,所以我承认所有的安全措施都不在那里。

我已经阅读了很多帖子并试图自己弄清楚,但我相信我在做一些根本错误的事情。

对此的任何帮助将不胜感激。众所周知,我会为那些帮助我编码的人买啤酒(通过贝宝):)

这是我现有的用于打印数据库结果的代码:

<?php
//This will connect to the database in order to begin this page
mysql_connect("localhost", "root", "time2start") or die (mysql_error());
//Now we will select the database we need to talk to
mysql_select_db("joomla_dev_15") or die (mysql_error());
$query = "SELECT * FROM enterprise_storage WHERE id=1";
$result = mysql_query($query) or die (mysql_error());
echo "<table border='1'>";
echo "$row";
echo "<tr> <th>Product</th> <th>Wayne Beeg</th> <th>Paul Hamke</th> <th>Steve Jaczyk</th>       <th>David Jontow</th> <th>Ed MacDonald</th> <th>Michael Munozcano</th> <th>Ron Shaffer</th>  <th>Luke Soares</th>  <th>Josh Wenger</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row['model'];
echo "</td><td>"; 
echo $row['beeg'];
echo "</td><td>"; 
echo $row['hamke'];
echo "</td><td>"; 
echo $row['jaczyk'];
echo "</td><td>"; 
echo $row['jontow'];
echo "</td><td>"; 
echo $row['macdonald'];
echo "</td><td>"; 
echo $row['munozcano'];
echo "</td><td>"; 
echo $row['shaffer'];
echo "</td><td>"; 
echo $row['soares'];
echo "</td><td>"; 
echo $row['wenger'];
echo "</td></tr>"; 
} 
echo "</table>";
?>
<FORM>
<INPUT TYPE="BUTTON" VALUE="Return to the Home Page"       ONCLICK="window.location.href='http://localhost/~user/joomla15/custom/skilldisplay.php'"> 
</FORM>
4

3 回答 3

1

也许

while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr>";
foreach($row as $content) {
    if($content == 0) {
        echo "<td style='background-color:gray;'>";
    }
    else {
        echo "<td style='background-color:green;'>";
    }
    echo $content . "</td>";
}
echo $row['wenger'];
echo "</td>"; 
}
echo "</tr></table>";
于 2012-04-10T19:59:35.290 回答
0

好的,所以我终于设法让它工作了。上面的两个回复帮助我找出了正确的方法来做到这一点。

当然,我的方法可能不是最好的方法,但我已经对其进行了测试,它可以满足我的需求。对于任何未来的搜索者,这就是我所做的:

    <?php
    //This will connect to the database in order to begin this page
    mysql_connect("localhost", "root", "time2start") or die (mysql_error());
    //Now we will select the database we need to talk to
    mysql_select_db("joomla_dev_15") or die (mysql_error());
    $query = "SELECT * FROM enterprise_storage";
    $result = mysql_query($query) or die (mysql_error());
    echo "<table border='1'>";
    echo "$row";
    echo "<tr> <th>Product</th> <th>Wayne Beeg</th> <th>Paul Hamke</th> <th>Steve Jaczyk</th> <th>David Jontow</th> <th>Ed MacDonald</th> <th>Michael Munozcano</th> <th>Ron Shaffer</th> <th><a href='http://localhost/~user/joomla15/custom/updateform.php'>Luke Soares</a></th> <th>Josh Wenger</th> </tr>";
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row['model'];
echo "</td>";
if ($row['beeg'] == '0'){
    echo '<td bgcolor="#FF0000">' . $row['beeg'] ;
}else{
    echo '<td>' .$row['beeg'];
}
echo "</td>"; 
if ($row['hamke'] == '0'){
    echo '<td bgcolor="#FF0000">' . $row['hamke'] ;
}else{
    echo '<td>' .$row['hamke'];
}
echo "</td>"; 
if ($row['jaczyk'] == '0'){
    echo '<td bgcolor="#FF0000">' . $row['jaczyk'] ;
}else{
    echo '<td>' .$row['jaczyk'];
}
echo "</td>"; 
if ($row['jontow'] == '0'){
    echo '<td bgcolor="#FF0000">' . $row['jontow'] ;
}else{
    echo '<td>' .$row['jontow'];
}
echo "</td>"; 
if ($row['macdonald'] == '0'){
    echo '<td bgcolor="#FF0000">' . $row['macdonald'] ;
}else{
    echo '<td>' .$row['macdonald'];
}
echo "</td>"; 
if ($row['munozcano'] == '0'){
    echo '<td bgcolor="#FF0000">' . $row['munozcano'] ;
}else{
    echo '<td>' .$row['munozcano'];
}
echo "</td>"; 
if ($row['shaffer'] == '0'){
    echo '<td bgcolor="#FF0000">' . $row['shaffer'] ;
}else{
    echo '<td>' .$row['shaffer'];
}
echo "</td>"; 
if ($row['soares'] == '0'){
    echo '<td bgcolor="#FF0000">' . $row['soares'] ;
}else{
    echo '<td>' .$row['soares'];
}
echo "</td>"; 
if ($row['wenger'] == '0'){
    echo '<td bgcolor="#FF0000">' . $row['wenger'] ;
}else{
    echo '<td>' .$row['wenger'];
}
echo "</td></tr>"; 

} 回声“”;

?>

于 2012-04-11T23:29:47.617 回答
0

尝试这样的事情

将此添加到您生成的文档中

<style type="text/css">
    .red{ background-color: red; }
</style>

这是你的 PHP:

<?php
// sanitize value
$value = trim($row['model']);
$class = (empty($value)) ? 'red' : '';

// display
echo "<td class=\"$class\">$value</td>"; 
...
?>
于 2012-04-10T20:00:10.057 回答