我目前正在为上传系统创建一个数据库 - 我正在使用一个选择框来限制添加到数据库中的类别数量。
<select name="category">
<?php
$conn = mysqli_connect("localhost", "blah", "blah") or die ("No connection");
mysqli_select_db($conn, "UPLOAD") or die("db will not open");
$query = "SELECT category FROM details GROUP BY category";
$result = mysqli_query($conn, $query) or die("Invalid query");
while($row = mysqli_fetch_array($result)) {
echo "<option value=\"" . $row[0] . "\">" . $row[0] . "</option>";
}
mysqli_close($conn);
?>
</select>
<select name="reaction">
<?php
$conn = mysqli_connect("localhost", "blah", "blah") or die ("No connection");
mysqli_select_db($conn, "UPLOAD") or die("db will not open");
$query = "SELECT reaction FROM details GROUP BY reaction";
$result = mysqli_query($conn, $query) or die("Invalid query");
while($row = mysqli_fetch_array($result)) {
echo "<option value=\"" . $row[0] . "\">" . $row[0] . "</option>";
}
mysqli_close($conn);
?>
虽然这两个查询是相同的 - 只有类别(顶部查询)停止从我的数据库中重复多个数据。当我查看我的数据库时 - 这就是我所发现的(我有预感可能是问题所在)。
INSERT INTO `details` (`name`, `category`, `reaction`, `photo`, `date_added`) VALUES
('Mase Laughing', 'Funny', 'Laugh\n', 'mase-laugh.gif', '2013-05-01 07:16:26'),
('Movie Wink', 'Cheeky', 'Wink\n', 'movie-wink.gif', '2013-05-02 12:33:12'),
('Tarzan Giggle', 'Funny', 'Wink\r\n', 'tarzan-laugh.gif', '2013-05-02 01:33:00');
除了反应之外,我还收到了这些奇怪的\r\n
信件——有人有什么想法吗?提前致谢。