2012-05-06 3 views
0
$.ajax({ 
     url: "notifications.php", 
     dataType: "json", 
     success: function(responseJSON) { 
      if (responseJSON.length > 0) { 
       document.title = document.title.replace(/^(?:\(\d+\))?/, "(" + responseJSON.length + ") ") 
       for (var i=0; i<10; i++) { 
        console.log(responseJSON[i].date_notify') 
       } 
      } 
     }, error : function(x) { 
      console.log(x.responseText) 
     } 
    }) 

의 'date_notify'내가 가지고있는이 오류를 속성을 읽을 수 없습니다 10 가지 결과를 원한다 ... 내 SQL 부분에 LIMIT 쿼리. 내 검색어는 여기자바 스크립트 catch되지 않은 형식 오류가 : 크롬에서 정의되지 않은

SELECT users.lastname, users.firstname, users.screenname, notifications.notify_id, 
notifications.tagged_by, notifications.user_id, notifications.post_id,               
notifications.type, notifications.action, notifications.date_notify, 
notifications.notify_id 
FROM website.users users INNER JOIN website.notifications notifications 
ON (users.user_id = notifications.user_id) 
WHERE notifications.user_id = ? and notifications.action = ? 
ORDER BY notifications.notify_id DESC 
//LIMIT 10 

이 방법을 변경하는 방법이 있습니까?

답변

1

사용은 AND는 루프에서 조건 에드 :

for(var i=0; i<responseJSON.length && i<10; i++) 

이 방법 루프가 둘 중 먼저 발생, 때 i 중 하나의 항목 수를 초과하거나 10에 도달 밖으로 잘라냅니다. 항목 수가 10보다 작은 경우 첫 번째 조건은 먼저 거짓이되고 10 개를 초과하는 레코드가 있으면 두 번째 조건이 먼저 거짓이됩니다.

+0

대단합니다! 고마워 형제는 그걸 몰랐어. –

1

SQL 쿼리를 제한하십시오. 사용하지 않을 데이터에 대해 네트워크 대역폭과 서버 리소스를 소비 할 이유가 없습니다. 데이터가 민감한 경우 잠재적 인 보안 문제는 없습니다.

관련 문제