嘿,我正在使用jQuery的autosuggest函數,我的問題是,當用戶從建議的值中選擇多個選項時,如何在php中分隔這些值,以便我可以將它們插入表中或其他東西?如何分離jQuery autosuggest值?
這裏的形式:
<table>
<form method="post" action="clippost.php" name="search">
<tr>
<td class="clip"><label><span><p class="signin">Clip Name:</p></span></label></td>
<td class="clip"><input type="text" name="clip" class="biginput" /></td>
</tr>
<tr>
<td class="clip"><label><span><p class="signin">Topic:</p></span></label></td>
<td class="clip"><input type="text" name="topic" class="biginput" /></td>
<td class="clip"><p class="info">Seperate by commas.</p></td>
</tr>
<tr>
<?php
$mysql=mysql_connect('localhost','***','***');
mysql_select_db('jmtdy');
$result=mysql_query("select * from users where username='".$_SESSION['username']."'") or die(mysql_error());
$dbarray=mysql_fetch_assoc($result);
$result2=mysql_query("select * from friendship where userid='".$dbarray['id']."'");
if(mysql_num_rows($result2)>0){
echo'
<td class="clip"><label><span><p class="signin">Clip-on people:</p></span></label></td>
<td class="clip"><input class="biginput" type="text" name="clippedon" id="suggestedfriend" /></td>
<td class="clip"><a class="neutral" href="faq.php#clipon"><p class="info">What is this?</p></a></td>
</tr>
';
}
else {
echo'
<td class="clip"><p class="signin">You need to have friends to clip-on people.</p></td>
<td class="clip"><a class="neutral" href="faq.php#clipon"><p class="info">What is this?</p></a></td>
';
}
?>
<tr><td class="clip"><label><span><p class="signin">Editable:</p></span></label></td><td><select name="editable">
<option value="edit">Yes</option>
<option value="noedit">No</option>
</select></td></tr>
<tr><td><input class="submitButton" type="submit" value="Create Clip" /> </td></tr>
</form>
</table>
而jQuery腳本:
<script type="text/javascript">
$(function(){
var data = {items: [
<?php
$mysql=mysql_connect('localhost','***','***');
mysql_select_db('jmtdy');
$result=mysql_query("select * from users where username='".$_SESSION['username']."'") or die(mysql_error());
$dbarray=mysql_fetch_assoc($result);
$result2=mysql_query("select * from friendship where userid='".$dbarray['id']."'");
while($dbarray2=mysql_fetch_assoc($result2)){
$result3=mysql_query("select * from users where id='".$dbarray2['friendid']."'");
$dbarray3=mysql_fetch_assoc($result3);
echo '{value: "'.$dbarray3['id'].'", name: "'.$dbarray3['username'].'"},';
}
?>
]};
$("#suggestedfriend").autoSuggest(data.items, {selectedItemProp: "name", searchObjProps: "name"});
});
</script>
而且clippost.php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" id="Cliproid" class=" no_js">
<head>
<link href='graphics/icon.png' rel='icon' type='image/png'/>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-language" content="en" />
<LINK REL=StyleSheet HREF="Mainstyles.css" TYPE="text/css"></link>
<Title>Cliproid</title>
</head>
<body>
<?php
$mysql=mysql_connect('localhost','*********','********');
mysql_select_db('jmtdy');
$clip=mysql_real_escape_string($_POST['clip']);
$topic=mysql_real_real_escape_string($_POST['topic']);
$editable=mysql_real_escape_string($_POST['editable']);
print_r($_POST['clippedon']);
?>
</body>
</html>
@JoukeWaleson當我print_r $ _POST或者當我回應它時,即使我選擇了值,我也什麼也沒得到。任何幫助? – 2011-02-06 17:31:48