问题描述
嘿大家,
我运行一个有员工提交的评论的网站,其中大部分是由一位作者写的
。但是,我们也做多重。评论。到目前为止,我只需拥有一个多个帐户的用户ID并在
下提交,但是这样会更难打印所有评论的列表由一个
的人,所以理想情况下我想做一个多选表格,这样我们就可以选择所有贡献者并将数值保存在数据库中 -
在一行中(类似于53,54,21等)。
我已经编写了一个多选表单,其中包含所有文章的作者br />
我的网站,并且我想将这个结果存储在一行中,所以我可以稍后将它们作为一个数组抓住它们 - 我怎么能这样做呢?我只是使用< select name =" author []">来搜索和使用< select name =" author []">在我的HTML中,然后
然后使用serialize()来处理它,但它失败了。当我在代码后运行
时,''multiplearray''的值保持为0,无论我是否
在表单上选择单个或多个值:
<?php
$ dbhost = ###
$ dbuser = ###
$ dbpass = ###
$ dbname = ###
$ conn = mysql_connect($ dbhost,$ dbuser,$ dbpass)或die(''Error
连接到mysql'');
mysql_select_db($ dbname);
if(isset($ _ POST [''save '']))
{
$ author = serialize($ _ POST [''author'']);
$ query =" INSERT INTO review_test(multiplearray)VALUES
(''$ author'')" ;;
mysql_query($ query)or die (''错误,查询失败'');
echo"查询成功!" ;;
}
echo "< form name =''test''method =''post''action =''''>" ;;
$ query2 =" SELECT Staff_ id,displayname FROM users WHERE
userlevel!= 0
ORDER BY username" ;;
$ result2 = mysql_query($ query2)or die( ''错误:''。
mysql_error());
echo"< select name =''author []''id =' 'author []''multiple =''multiple''
size ='''10''>" ;;
while($ row2 = mysql_fetch_array($ result2) ,MYSQL_NUM))
{
list($ Staff_id,$ displayname)= $ row2;
echo"< option value =' '$ Staff_id''> $ displayname< / option>" ;;
}
echo"< / select>" ;;
echo"< br>< br>< input name =''save''type =''submit''id =''save''value =''帖子
评论''>" ;;
echo"< / form>" ;;
?>
-----
马特
Hey everyone,
I run a site with staff-submitted reviews, and most of them are written
by one author. However, we also do "multiple" reviews. Up until now I
just had a userid for a ''Multiple'' account and submitted them under
that, but this makes it harder to print lists of all the reviews by one
person, so ideally I wanna make a multiple select form so we can just
select all the contributors and have the values saved in the database -
in one row (something like "56,34,21" etc).
I''ve coded a multiple select form with all the authors of articles for
my site on, and I want to store the results of this in one row so I can
grab them as an array later - how can I go about doing this? I just
googled and came across using <select name="author[]"> in my HTML, and
then using serialize() to process it, but it fails. When I run the
following code, the value for ''multiplearray'' remains at 0 whether I
select single OR multiple values on the form:
<?php
$dbhost = ###
$dbuser = ###
$dbpass = ###
$dbname = ###
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (''Error
connecting to mysql'');
mysql_select_db($dbname);
if(isset($_POST[''save'']))
{
$author = serialize($_POST[''author'']);
$query = "INSERT INTO review_test (multiplearray) VALUES
(''$author'')";
mysql_query($query) or die(''Error ,query failed'');
echo "Query successful!";
}
echo "<form name=''test'' method=''post'' action=''''>";
$query2 = "SELECT Staff_id, displayname FROM users WHERE
userlevel !=0
ORDER BY username";
$result2 = mysql_query($query2) or die(''Error : '' .
mysql_error());
echo "<select name=''author[]'' id=''author[]'' multiple=''multiple''
size=''10''>";
while($row2 = mysql_fetch_array($result2, MYSQL_NUM))
{
list($Staff_id, $displayname) = $row2;
echo "<option value=''$Staff_id''>$displayname</option>";
}
echo "</select>";
echo "<br><br><input name=''save'' type=''submit'' id=''save'' value=''Post
Review''>";
echo "</form>";
?>
-----
Matt
推荐答案
这篇关于将数组存储在一行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!