0

目前我有一个脚本可以显示可编辑的数据并且可以更新数据库。我试图输入行数,但似乎没有任何效果。我真的很喜欢制作 3 列(每列 10 行)的脚本,请帮忙。

$sql = "SELECT id, pounds FROM price_list ORDER BY id";
$i = 0;
$result = mysql_query($sql); 
echo "<form name='prices' method='post' action='updateA.php'>"; 

while($rows = mysql_fetch_array($result)) 
{
echo "<body bgColor='#5F5F6B'>";
echo "<table><table border=2 cellspacing=0 cellpadding=1>";
echo "<input type='hidden' name='id[$i]' value='{$rows['id']}' >"; 
echo "<td><font color='#FFFFFF'><font size='2'>DAYS {$rows['id']}: </font><font size='2'><font color='#000000'>PRICE:<input type='text' size='1' name='pounds[$i]'  value='{$rows['pounds']}' ></tr>";

++$i;
}
echo "</table>";
echo "<input type='submit' value='Update Prices Band A' />"; 
echo "</form>"; 

?>

以上是原代码。

4

2 回答 2

0

首先非常感谢 Leonard Pauli,该代码在显示数据方面表现出色,但是它不会使用我的 update.php 更新数据库。下面是我试图存档的修改后的代码和屏幕截图。

以 3 列显示的单行数据的屏幕截图

<style>

body {
    background:#5F5F6B;
    color:#fff;
    width:800px;
    height:550px;
    border:2px solid #bbb;
    padding:20px;
    float:center;
}
input[type="text"] {
width: 30px;
}
.table {
    width:180px;
    margin:1px;
    border:2px solid #bbb;
    padding:10px;
    float:left;
}
.header {
    width:595px;
    margin:1px;
    border:2px solid #bbb;
    padding:10px;
    float:left;
}
</style>
<div class="header"><b>Price List for dates from <font color ="yellow"><?php echo   "$SPA"; ?> to <?php echo "$EPA"; ?></font></div>


<?php
$dataprice = $_POST['database'];
$datesrange = $_POST['id'];

$result = mysql_query("SELECT id, pounds FROM $dataprice ORDER BY id");

echo '<form name="prices" method="POST" action="update.php">'; 

$i = 0;
while ($rows = mysql_fetch_array($result)) {
    echo '<div class="table">Day <font color="yellow">'.$rows['id'].' </font> costs ';
    echo "<input type='hidden' name='id[$i]' value='{$rows['id']}' >";
    echo "<input type='text' name='pounds[$i]' value='{$rows['pounds']}' > Pounds";
    echo '<br/></div>';

    $i++;
}

echo "<input type='hidden' name='databases' value='$dataprice'>";
echo '<center><input type="submit" value="Update Prices"/>'; 
echo '<center><font color="yellow"><br><br><br>IF UPDATING PRICE BAND D, ONLY ENTER THE VALUE OF WHICH 
PRICES YOU WANT TO INCREASE BY, <br>EXAMPLE: 7 DAYS, IF CURRENT PRICE IS 30, IF YOU WANT TO 
CHARGE 34, ONLY ENTER 4 AND LEAVE EVERYTHING ELSE SET TO 0</b></center>';
echo "</form>";


?>

真的有点白痴,完全忘记了 CSS 样式。

于 2013-07-31T07:42:19.270 回答
0

我真的不知道您要做什么,但是此代码将生成数据库中所有条目的列表,并且能够更改它们。请注意,您必须重新制作 update_a.php 文件:

<style>

    body {
        background:#5F5F6B;
        color:#fff;
    }

</style>

<?php

$result = mysql_query("SELECT id, pounds FROM price_list ORDER BY id");
if (!$sql || mysql_num_rows($result)==0)
    echo "Price list is empty";
else {
    echo '<form name="prices" method="GET" action="update_a.php">'; // Change your filename!

    $i = 0;
    while ($rows = mysql_fetch_array($result)) {
        echo 'Day '.$rows['id'].' costs ';
        echo '<input type="text" name="'.$rows['id'].'" value="'.$rows['pounds'].'"/> pounds'
        echo '<br/>'

        $i++;
    }
    echo '<input type="submit" value="Update Prices Band A"/>'; 
    echo "</form>";
}

?>
于 2013-07-29T12:23:39.403 回答