Re: [PHP] calling a function in the same page

2006-12-26 Thread Ryan Fielding

Jahangir wrote:

I am trying to call a function from a href inside the same page.
this is the code:
echo brbra 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
hangirquery=' .urlencode($query). 'output=phpresults=100site=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 brNO RESULTS TO DISPLAY; }

echo tr; echo h4 style=\color:#FF\ 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

  

why not use a temporary variable?

$temp = isearch($query);

echo br /br /a href=\ . $temp . \More results from Mysite/a;

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] calling a function in the same page

2006-12-26 Thread Aras


You can not call PHP functions through a href which is used for linking web
pages.
You need to create a new file or use a switch in your current file for
search input,
with the function in it. So that you can link to that URL, not the function
itself.

You can use AJAX as well, to send commands to a php file and get the results
in xml/text,
but again you need to call Javascript there, your logic is totally wrong.


Aras Koktas
[EMAIL PROTECTED]
Business Excellence Development
Phi.dot Internet Systems


-Original Message-
From: Jahangir [mailto:[EMAIL PROTECTED]
Sent: Sunday, December 24, 2006 6: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 brbra 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
hangirquery=' .urlencode($query). 'output=phpresults=100site=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 brNO RESULTS TO DISPLAY; }

echo tr; echo h4 style=\color:#FF\ 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] calling a function in the same page

2006-12-26 Thread Peter Lauri
This is what you could do. Separating them into a few files. Also read the
http://en.wikipedia.org/wiki/Ajax_%28programming%29 to learn some more about
AJAX.

You should also learn more about Server Side Scripting so you understand
what can be done with Server Side Scripting and Client Side Scripting.


index.php:

$query would contain the SQL (or is it some other query type) you want to
execute. This is far from any security as you come if this would be SQL, as
you would output the SQL and therefore give table names etc to anyone who
views the source of the HTML. This could in the future lead to SQL
injections etc if you don't protect your self against that as well. 

You would also need to include the javascript.js in your head tag of the
HTML that you generate. Also you would need to download the Prototype
library and include them in head as well. See
http://wiki.script.aculo.us/scriptaculous/show/Prototype where you can
download the necessary files to do your AJAX calls. If you want to do it the
hard coded way you need to create an ActiveXObject object if the user have
IE or an XMLHttpRequest object if user don't have a IE compatiable browser.
I suggest that you stick with Prototype unless you need to create an really
high performance tool for this, and might need to hard code it your self.

--
echo brbra href=\javascript:doSearch($query)\More results from
Mysite/a;
echo div id='resultsdiv'/div;
--



javascript.js:

--
function doSearch(sql) {
var success = function(t){
thediv = document.getElementById(resultsdiv);
thediv.innerHTML = t.responseText;
}

var failure = function(t){
alert(Something went wrong, please try again.);
}

var url='ajax.php';

pars = query=+ query;

var req= new Ajax.Request(url, {method: 'post', postBody:pars,
onSuccess: success, onFailure: failure});

}
--



ajax.php

--
//Set header to TEXT/HTML and also whatever enc type you want.
header(Content-type: text/html);

if(isset($_POST['mysql'])) {
//do whatever you want with the
//$_POST['mysql'] variable and output the results
//the you want to be shown in the div with id resultsdiv
}
--


Best regards,
Peter Lauri


-Original Message-
From: Aras [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 26, 2006 11:50 AM
To: php-general@lists.php.net
Subject: RE: [PHP] calling a function in the same page



You can not call PHP functions through a href which is used for linking web
pages.
You need to create a new file or use a switch in your current file for
search input,
with the function in it. So that you can link to that URL, not the function
itself.

You can use AJAX as well, to send commands to a php file and get the results
in xml/text,
but again you need to call Javascript there, your logic is totally wrong.


Aras Koktas
[EMAIL PROTECTED]
Business Excellence Development
Phi.dot Internet Systems


-Original Message-
From: Jahangir [mailto:[EMAIL PROTECTED]
Sent: Sunday, December 24, 2006 6: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 brbra 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
hangirquery=' .urlencode($query). 'output=phpresults=100site=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 brNO RESULTS TO DISPLAY; }

echo tr; echo h4 style=\color:#FF\ 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] calling a function in the same page

2006-12-25 Thread Jahangir
I am trying to call a function from a href inside the same page.
this is the code:
echo brbra 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
hangirquery=' .urlencode($query). 'output=phpresults=100site=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 brNO RESULTS TO DISPLAY; }

echo tr; echo h4 style=\color:#FF\ 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



Re: [PHP] calling a function in the same page

2006-12-25 Thread Sumeet

Jahangir wrote:

I am trying to call a function from a href inside the same page.
this is the code:
echo brbra 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
hangirquery=' .urlencode($query). 'output=phpresults=100site=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 brNO RESULTS TO DISPLAY; }


add a 'die;' here.. like

{
echo brNO RESULTS TO DISPLAY;
die;
}

--
Thanking You

Sumeet Shroff
http://www.prateeksha.com
Web Designers and PHP / Mysql Ecommerce Development, Mumbai India

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] calling a function in the same page

2006-12-25 Thread Peter Lauri
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:[EMAIL PROTECTED] 
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 brbra 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
hangirquery=' .urlencode($query). 'output=phpresults=100site=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 brNO RESULTS TO DISPLAY; }

echo tr; echo h4 style=\color:#FF\ 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] calling a function in the same page

2006-12-25 Thread Jahangir
I am trying to call a function from a href inside the same page.
this is the code:
echo brbra 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
hangirquery=' .urlencode($query). 'output=phpresults=100site=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 brNO RESULTS TO DISPLAY; }

echo tr; echo h4 style=\color:#FF\ 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



[PHP] calling a function in the same page

2006-12-24 Thread Jahangir
I am trying to call a function from a href inside the same page.
this is the code:
echo brbra 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
hangirquery=' .urlencode($query). 'output=phpresults=100site=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 brNO RESULTS TO DISPLAY; }

echo tr; echo h4 style=\color:#FF\ 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



[PHP] calling a function in the same page

2006-12-24 Thread Jahangir
I am trying to call a function from a href inside the same page.
this is the code:
echo brbra 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
hangirquery=' .urlencode($query). 'output=phpresults=100site=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 brNO RESULTS TO DISPLAY; }

echo tr; echo h4 style=\color:#FF\ 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