我这里有问题。我需要进入$pilihdomain
searh_request.php才能在search_response.php中使用
我还没有访问它。
我这样定义:
设置.php
<?php
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "";
$dbname = "skripsi";
$pilihdomain=$_POST['cmake'];
global $pilihdomain;
?>
search_request.php
<script src='jquery.min.js'></script>
<script>
jQuery(document).ready(function($) {
// Run when Search button is clicked
$('#search_button').click(function(){
// This can take a few seconds so display progress text
$('#search_results').html('Searching Twitter...');
// Get the value of the input field
// Encode it for use in a URL
var search_value = encodeURIComponent($('input[name=search_terms]').val());
// Send the search terms to the server in an Ajax request
// This URL is for illustration only
// You MUST change it to your server
$.ajax({
url: 'http://localhost/kejar/code/search_response.php?q=' + search_value,
success: function(data){
// Display the results
$('#search_results').html(data);
}
})
})
});
</script>
<?php require_once 'settings.php'; ?>
Search:
<input name='search_terms' autofocus='autofocus'/>
<?php
$db = mysql_connect($dbHost,$dbUser,$dbPass);
mysql_select_db($dbname,$db);
$sql = mysql_query("SELECT * FROM namaklasifier");
while($row = mysql_fetch_array($sql)) {
$clsfr = $row['username'];
$sql = mysql_query("SELECT * FROM namaklasifier");
echo '<select name="cmake" autofocus width="10">';
echo '<option value="0">-Pilih Domain Klasifikasi-</option>';
while($row = mysql_fetch_array($sql)) {
echo '<option ' . ($clsfr==$row['username']) . ' value="'.$row['username'].'">'.$row['username'].'</option>';
}
echo '</select>';
}
?>
<button id='search_button'>Search</button>
<div id='search_results'></div>
search_response.php
<
?php
require_once("uClassify.php");
require_once 'settings.php';
$uclassify = new uClassify();
$uclassify->setReadApiKey('8DvvfxwKPdvjgRSrtsTSOawmQ0');
$uclassify->setWriteApiKey('v4Us59yQFhf9Z0nGrQsrTtzBI5k');
if (!empty($_GET['q'])) {
// Strip any dangerous text out of the search
$search_terms = htmlspecialchars($_GET['q'].' -RT -@smartfrenworld -@smartfrencare -from:smartfrencare -from:smartfrenworld');
// Create an OAuth connection
require 'app_tokens.php';
require 'tmhOAuth.php';
$connection = new tmhOAuth(array(
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret,
'user_token' => $user_token,
'user_secret' => $user_secret
));
// Run the search with the Twitter API
$http_code = $connection->request('GET',$connection->url('1.1/search/tweets'),
array('q' => $search_terms,
'count' => 20,
'lang' => 'in',
'locale' => 'jakarta',
'result_type' => 'recent'));
// Search was successful
if ($http_code == 200) {
// Extract the tweets from the API response
$response = json_decode($connection->response['response'],true);
$tweet_data = $response['statuses'];
// Accumulate tweets from search results
$tweet_stream = '';
foreach($tweet_data as $tweet) {
// Ignore retweets
if (isset($tweet['retweeted_status'])) {
continue;
}
$resp = $uclassify->classify($tweet['text'], **$pilihdomain**, 'herlambangp');
$value = print_r($resp,true) ;
// Add this tweet's text to the results
$tweet_stream .= $tweet['text'].' | '.$value.'<br/>';
}
// Send the result tweets back to the Ajax request
print $tweet_stream;
// Handle errors from API request
} else {
if ($http_code == 429) {
print 'Error: Twitter API rate limit reached';
} else {
print 'Error: Twitter was not able to process that search';
}
}
} else {
print 'No search terms found';
}
?>
谢谢你的帮助。