我有一个多选列表(链接),它将值发布到 $links。然后,我想对表“链接”运行查询,返回与 $links 中的值匹配的记录。我正在使用以下代码,但没有得到任何结果:
<select name="links[]" size="9" multiple="multiple" id="links">
<?php
$query = mysql_query("SELECT * from link ORDER BY link_title ASC");
for($i=0;$i<mysql_num_rows($query);$i++) {
$row=mysql_fetch_assoc($query);
?>
<option value="<?php echo $row['link_pk']; ?>"><?php echo $row['link_title']; ?></option>
<?php
}
?>
</select>
和提交代码:
$author_pk = $_GET['author_pk'];
$title = $_POST['title'];
$topic_introduction = $_POST['topic_introduction'];
$selected_topic = $_POST['selected_topic'];
$links = $_POST['links'];
$majors = $_POST['majors'];
$majors_string = implode(",", $majors);
$sub_discipline = $_POST['sub_discipline'];
if(isset($_POST['submit'])){
$query_links = "SELECT * FROM link WHERE link_pk IN ('.implode(',',$links).')";
$result_links = mysql_query($query_links, $connection) or die(mysql_error());
while ($row_links = mysql_fetch_assoc($query_links)){
$topic_links = array();
$topic_links[$row_links['url']] = $row_links;
} if($result_links){
$topic = $topic_introduction . '<p>' . $topic_links;
$query = "INSERT INTO topic (topic_pk,title,topic,majors,sub_discipline_fk,author_fk,created)
VALUES ('','$title','$topic','$majors_string','$sub_discipline','$author_pk',NOW())";
$result = mysql_query($query, $connection) or die(mysql_error());
if($result){
$message = "- The topic '" . $title . "' has been created";
}
}
}