473,493 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

calling a php function

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

Dec 24 '06 #1
3 2500
no
thecoolone wrote:
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

you must break a string to call a function.
try this:

echo "<br><br><a href=\"" . isearch($query) . "\">More results from
Mysite</a>";
Dec 24 '06 #2
no
oh, yeah
and first write your function

function isearch() {
....

}

and then call the

echo "<br><br><a href=\"" . isearch($query) . "\">More results from
Mysite</a>";
Dec 24 '06 #3

thecoolone wrote:
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
It's not clear what you're wanting to do.
a) Do you want a link that executes/calls isearch?
b) Or, do you want the href link/value to contain the results of
isearch?

I'm thinking you want (a). If so, try something like this:
echo '<br><br><a
href="?action=search&amp;query='.urlencode($query) .'">More
results</A>';

then you'd need to add some code to your page likey so:

if ( isset($_GET['action']) && $_GET['action'] == 'search' )
{
if ( !empty($_GET['query']) )
isearch($_GET['query']);
}

Dec 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2934
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
6
3294
by: jchao123 | last post by:
Dear All, I have an MDB file (Access 2000/XP) which contains generic routines I use in various apps (eg, API calls, File access classes etc). I have compiled into an MDE file which I reference...
14
2976
by: ericellsworth | last post by:
Hi, I'm trying to use a class to pass variables back and forth from a form opened in dialog mode. I have created a class which invokes a form in its show method, like so: Public Sub Show() '...
1
2880
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code...
5
3392
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
2
3136
by: Geler | last post by:
A theoretical question: Sorry if its a beginner question. Here is a quote from the MSDN explaning the C/C++ calling convention.. It demonstrates that the calling function is responsible to clean...
18
4309
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
15
22790
by: dspfun | last post by:
Hi, Is it possible to print the function name of the calling function? For example, f1() and f2() both calls f3(), in f3() I would like to print the name of the function calling f3() which...
11
3167
by: briankirkpatrick | last post by:
Forgive me if my post seems a little amateurish... I'm requesting assistance from some of you smart folks out there to get the managed calls write that meet the specification in the esa.h for...
16
517
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
0
7119
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.