2012-07-10 2 views
2

그래서 내 데이터베이스에 ID와 Visit_Count INT가있는 inspirationWall이라는 테이블을 만들었습니다. 을 입력하고 id = 1 및 Visit_Count = 2 인 행을 추가하십시오.자바 스크립트에서 wordpress 데이터베이스에서 값 검색

Wordpress에서 Visit_Count의 값을 검색하고 테스트 용으로 경고에 값을 표시하려고합니다.

필자 내가 내 코드를 만든 것을 보면이 예를 그래서

<?php $user_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->users;")); echo "<p>User count is {$user_count}</p>";?> 

를 워드 프레스 사본을 다음과 사용

var $inspirationWall_Count = 0; 

$inspirationWall_Count = $wpdb->get_var($wpdb->prepare("SELECT Visit_Count FROM $wpdb- >inspirationWall WHERE id=1;")); 

alert($inspirationWall_Count); 

이 값을 검색하고로 저장하지 않는 것 $ inspirationWall_Count.

내가 뭘 잘못하고 있니?

감사

당신은 JS와 함께 할 필요가 PHP로 경고를 할 수 없습니다

답변

0

,

다시로 var $inspirationWall_Count = 0;를 정의 할 필요가 없습니다 그, PHP 작동하지

여기 무엇을해야할까요?

$inspirationWall_Count = 0; 
$inspirationWall_Count = $wpdb->get_var($wpdb->prepare("SELECT Visit_Count FROM $wpdb- >inspirationWall WHERE id=1;")); 
echo '<script>alert('.$inspirationWall_Count.')</script>'; 
관련 문제