RE: [PHP] calling a function in the same page
| From: | Peter Lauri | Date: | Mon, 25 Dec 2006 21:07:49 +0000 |
| Subject: | RE: [PHP] calling a function in the same page | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-246212@lists.php.net to get a copy of this message | ||
Hi,
Are you trying to use PHP as a client scripting language?
What you are doing cannot be done with plain PHP, you have to invoke
JavaScript or similar to make a HTTP request and then parse it.
Search Google for "AJAX" and you could get it working using that. Prototype
is a easy to use JS library that you can do "AJAX" requests with and then do
what you want with by DOM.
/Peter
-----Original Message-----
From: Jahangir [mailto:jahan9@gmail.com]
Sent: Sunday, December 24, 2006 5:34 PM
To: php-general@lists.php.net
Subject: [PHP] calling a function in the same page
I am trying to call a function from "a href" inside the same page.
this is the code:
echo "<br><br><a href=\"isearch($query)\">More results from
Mysite</a>";
// calling the function isearch
function isearch($query)
{$query=urlencode($query);
$request='http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=Ja
hangir&query=' .urlencode($query).
'&output=php&results=100&site=mysite.com;
$response=file_get_contents($request);
if ($response === false) {
die('Request failed');}
$phpobj=unserialize($response);
$count=$phpobj["ResultSet"]["totalResultsReturned"];
if($phpobj["ResultSet"]["totalResultsAvailable"]==0)
{echo "<br>NO RESULTS TO DISPLAY"; }
echo "<tr>"; echo "<h4 style=\"color:#FF0000\"
align=\"center\">Results from
Mysite</h4>";
for($i=0;$i<$count;$i++)
{ echo '<pre>';
$no=$i+1;
$url=$phpobj["ResultSet"]["Result"]["$i"]["Url"];
echo "<h3>" ."$no. ". "<a href=\"$url\">" .
$phpobj["ResultSet"]["Result"]["$i"]["Title"] .
"</a></h3>"; echo "</tr>";
echo "<tr>"; echo
$phpobj["ResultSet"]["Result"]["$i"]["Summary"]; echo
"</tr>";
echo "<br>"; echo "<tr>"; echo "<b>"
.$phpobj["ResultSet"]["Result"]["$i"]["Url"]
."</b>"; echo "</tr>";
echo "<br>";
$link=$phpobj["ResultSet"]["Result"]["$i"]["DisplayUrl"];
echo "<tr>"; echo "<a href=\"$url\">$link</a>"; echo
"</tr>";
echo '</pre>'; }}
whenever i try to execute this function i either get an "Object not found
error" or "Access Forbidden error".
Can someone tell me where am i going wrong here??
thanks in advance
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php