[英]how to change website background using php and mysql?
我在更改背景時遇到問題,僅當圖像id = 1時,它始終顯示或更改背景,我如何才能顯示其他值?
這是我的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:
<style type="text/css">
body {
background-image: url(<?php echo $page_color; ?>);
</style>
這是顯示照片的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>
為什么要在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>
這將為您提供所有選擇,現在您可以使用其他html代碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.