gpt4 book ai didi

php - 如何使用php和mysql更改网站背景?

转载 作者:行者123 更新时间:2023-11-29 03:30:28 27 4
gpt4 key购买 nike

我在更改背景时遇到问题,它总是仅在图像 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 并将它们添加到一个 string[] 中,你可以再次为所有颜色选项创建新的 while on 选项

<?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 代码

关于php - 如何使用php和mysql更改网站背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31352423/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com