[英]how to change website background using php and mysql?
i have an issue changeing the background , it always show or change the background only if the image id =1 , how can i dysplay other values ? 我在更改背景时遇到问题,仅当图像id = 1时,它始终显示或更改背景,我如何才能显示其他值?
here is my php code : 这是我的PHP代码:
<?php
include "config.php"; //Database connection file
//Check the database for background color
$check_page_color = mysql_query("select * from `page_color` where `id` = '".mysql_real_escape_string('1')."'"); // where `id` = '".mysql_real_escape_string('1')."'
if(mysql_num_rows($check_page_color) > 1) //If no color is found, use the default color below > 1
{
$page_color = "#F9F9F9"; //Default Color
}
else
{
$get_page_color = mysql_fetch_array($check_page_color);
$page_color = strip_tags($get_page_color["background_color"]); //Color from the database
}
?>
CSS : CSS:
<style type="text/css">
body {
background-image: url(<?php echo $page_color; ?>);
</style>
and here is the HTML code that displays the photos : 这是显示照片的HTML代码:
New Background:<select name="img" class="vpb_field" id="color" style="height: 40px; width: 151px" >
<option><?php echo $page_color; ?></option>
</select>
<span class="vpb_general_button" onclick="vpb_submit_form();">Submit</span>
Why you taking 1 id in mysql you can take all with while and add them in a string[] and again you can make new while on option for all color options 为什么要在mysql中使用1个id,您可以同时使用所有的while并将它们添加到字符串中[],然后您可以为所有颜色选项重新设置while设置
<?php $page_color = mysql_query("select * from `page_color`");
$counter = 0;
$i = 0;
while($showall = mysql_fetch_array($page_color))
{
extract($showall);//<-- we cut your data hire
$counter++;
$array_colors[] = $color; // <-- This is your mysql col
?>
<select name="img" class="vpb_field" id="color" style="height: 40px; width: 151px" >
<?php while($i < $counter) // <-- You can change this if u want size_of
{echo '<option>'. $array_colors[$i] .'</option>';}
?>
</select>
this will give you all options now ucan use your other html code 这将为您提供所有选择,现在您可以使用其他html代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.