2013-08-30 2 views
0

다음 코드는 test2.php과 관련되어 있습니다. 내 문제는 메뉴에서 선택한 사용자를 고유 ID와 연결해야하므로 URL은 선택한 사용자의 페이지가됩니다. 문제는 id가 정의되지 않았다는 것입니다.MySQL에서 값을 복구 할 수 없습니다

그리고 이유를 모르겠습니다! 내가 도대체 ​​뭘 잘못하고있는 겁니까?

window.location.href = '/profile.php?id='+pieces[1]; 

에서 제공되는 URL은 /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"; 
} 
?> 
+0

시도가 개를 기록하고'을 console.log (조각)가 무엇을보고' – Sedz

+0

그것은 아무것도 ... – freddy

답변

1

을 시도해보십시오

$("#course").autocomplete("/test/test2.php", { 
     delay: 0, 
     selectFirst: false, 
     formatItem: function(data, i, n, value) { 
     //make the suggestion look nice 
     var pièces = value.split("::"); 
       return "<font color='#000000'; font size='3pt'; font face='Arial'>" + pièces[0] + "</font>"; 
     }, 
     formatResult: function(data,value) { 
      //only show the suggestions and not the URLs in the list 
     var pièces = value.split("::"); 

       return pièces[0]; 

     } 
    }).result(function(event, data, formatted) { 
    //redirect to the URL in the string 

    var pieces = formatted.split("::"); 
      window.location.href = '/profile.php?id='+pieces[1]; 

을 두 번째 코드는

당신은 추가해야 :

$id = $rs['id']; 

$cname = $rs['Username']; 

에서이 다음 행으로 변경 추가 할 수 있습니다.

echo (utf8_encode("$cname::$id\n")); 
1

실제로 포함 스크립트에서 /test/test2.php 퍼팅 생각하지 않는다 test2.php를 실행하십시오.

이 하나를 교체해야합니다, 당신의 첫 번째 코드의 경우이

$("#course").autocomplete("<?php include '/test/test2.php'; ?>", { 
관련 문제