I am using a simple form to set the name of a hashtag into a php file but I want the results to be displayed on the same page as the form.
My form and php is as follows
<form id"search" method="post" action="twitter.php">
<input type="text" name="hash" id="hash"/>
<input type="submit" name="submit" value="submit"/>
</form>
My php displays the results of a hash tag search
<?php
global $total, $hashtag;
$hashtag = $_POST["hash"];
$total = 0;
function getTweets($hash_tag, $page) {
global $total, $hashtag;
$url = 'http://search.twitter.com/search.json?q='.urlencode($hash_tag).'&';
$url .= 'page='.$page;
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
$json = curl_exec ($ch);
curl_close ($ch);
echo "<pre>";
$json_decode = json_decode($json);
print_r($json_decode->results);
$json_decode = json_decode($json);
$total += count($json_decode->results);
if($json_decode->next_page){
$temp = explode("&",$json_decode->next_page);
$p = explode("=",$temp[0]);
getTweets($hashtag,$p[1]);
}
}
echo $total;
getTweets($hashtag,1);
?>
What should I do to get the results of the php to display on the same page as below the form
Thanks in advance
Post it to the same page, you define an action in your form “twitter.php” this means the form will go to the page twitter.php with the post information.
If you post it to the same page, catch the post request there and display whatever was requested there either below or above the form both elements are shown on the page.
Small example:
this will display a form with an input field for the hashtag. the script is posted to the same page, the PHP catches the POST request and displays whatever is searched. Instead you could use this value to retrieve the search action from twitter itself.