我有一个脚本,当用户选择一种颜色时,它成功地将十六进制颜色代码存储在数据库中。我如何显示这个颜色,是存储在我的数据库在我的页面color.php
,而不是显示十六进制的颜色代码的图片存储在数据库中?
color.php
<?php
$con=mysqli_connect("localhost","root","root","car");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT * FROM general";
$records=mysqli_query($con,$sql);
?>
<table class="table table-striped table-hover table-bordered datatable">
<tbody>
<?php
$result = mysqli_query($con,"SELECT * FROM general WHERE sex ='male' ");
$count = mysqli_num_rows($result);
while($row=mysqli_fetch_array($result)){
?>
<tr>
<td><center><input type="checkbox" name="check[<?php echo $row['general_id'];?>]" value="1" ></center> </td>
<td><input type="" name="f_name[]" value="<?php echo $row['f_name'];?>"></label></td>
<td><input style="width: 100px" type="" name=" color[]" value="<?php echo $row['color'];?>"></label></td>
<td><input type="" name="options[]" value="<?php echo $row['options'];?>"></label></td>
<td><input style="width: 100px" type="" name="comment[]" value="<?php echo $row['comment'];?>"></label></td>
</tr>
<?php } //end of while loop?>
</tbody>
</table>
试着给这个颜色的单元格设置你的内联颜色的背景色,像这样:
<tr>
<td><center><input type="checkbox" name="check[<?php echo $row['general_id'];?>]" value="1" ></center> </td>
<td><input type="" name="f_name[]" value="<?php echo $row['f_name'];?>"></label></td>
<td style="background-color:<?php echo $row['color'];?>;"><input style="width: 100px" type="" name=" color[]" value="<?php echo $row['color'];?>"></label></td>
<td><input type="" name="options[]" value="<?php echo $row['options'];?>"></label></td>
<td><input style="width: 100px" type="" name="comment[]" value="<?php echo $row['comment'];?>"></label></td>
</tr>
你也可以给你的文本颜色的十六进制颜色,你存储在数据库中,甚至整个行,这一切都取决于你。