我有以下代碼,這與test2.php
有關。我的問題是,我必須將菜單中選擇的用戶與其唯一ID關聯起來,因此該URL將成爲所選用戶的頁面。問題是,該ID是未定義的。無法從MySQL中恢復值
而我不知道爲什麼!我究竟做錯了什麼?是來自
window.location.href = '/profile.php?id='+pieces[1];
網址爲/profile.php?id=undefined
$("#course").autocomplete("/test/test2.php", {
selectFirst: false,
formatItem: function(data, i, n, value) {
//make the suggestion look nice
return "<font color='#3399CC'>" + value.split("::")[0] + "</font>";
},
formatResult: function(data,value) {
//only show the suggestions and not the URLs in the list
return value.split("::")[0];
var username = splitItems[0];
var id = splitItems[1];
return username;
}
}).result(function(event, data, formatted) {
//redirect to the URL in the string
var pieces = formatted.split("::");
window.location.href = '/profile.php?id='+pieces[1];
test2.php
<?php
mysql_connect ("****", "****","****") or die (mysql_error());
mysql_select_db ("****");
$q = strtolower($_GET["q"]);
if (!$q) return;
$sql = "select Username, id from **** where Username LIKE '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
$cname = $rs['Username'];
echo "$cname\n";
}
?>
嘗試記錄這些碎片,看看它有什麼'console.log(件)' – Sedz
它沒有什麼... – freddy