Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need to use a var to reference array
Old 07-26-2010, 10:42 AM Need to use a var to reference array
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
I have the following script for a bing search it receives a request from client and will return a formatted string via ajax... problem I have is using var for reference, can someone provide correct syntax? I want to replace the underlined "Web" with $type

Code:
<?php
$term="bodyguard";
$type="Web";
$count="10";
$ch = curl_init(); 
$timeout = 0; // set to zero for no timeout 
curl_setopt ($ch, CURLOPT_URL, "http://api.bing.net/json.aspx?AppId=71D2A914321DB8A271270F748F0F5A3C4B4B4763&Market=en-US&Query=".$term."&Sources=".$type."&".$type.".Count=".$count."&JsonType=raw");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
$search = curl_exec($ch); 
curl_close($ch);
$Response = json_decode($search,true);
    foreach($Response[SearchResponse][Web][Results] as $item){
    echo("        
                            <div class='style4' style='margin-left:1em; margin-right:1em'>".$item[Title]."</div>
                            <div class='style6' style='margin-left:1em; margin-right:1em'>".$item[Description]."</div>
                            <div class='style4' style='margin-left:1em; margin-right:1em'><a href='".$item[Url]."' target='_blank'>".$item[Url]."</a></div>
                        <br>
                    ");
    }echo $Response;
?>
__________________
Sleeping Troll, EMUSE, Mind Expansion...Truly serendipity!

Last edited by Sleeping Troll; 07-26-2010 at 10:55 AM..
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-26-2010, 10:58 AM Re: Need to use a var to reference array
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Doh! (slap) OK got it, was trying to make it too complicated!
__________________
Sleeping Troll, EMUSE, Mind Expansion...Truly serendipity!
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 07-26-2010, 08:03 PM Re: Need to use a var to reference array
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Please post your working code if other people with the same question come along
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 07-31-2010, 12:45 AM Re: Need to use a var to reference array
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
OK, real simple!

PHP Code:
<?php
$term
="bodyguard";
$type="Web";
$count="10";
$ch curl_init(); 
$timeout 0// set to zero for no timeout 
curl_setopt ($chCURLOPT_URL"http://api.bing.net/json.aspx?AppId=71D2A914321DB8A271270F748F0F5A3C4B4B4763&Market=en-US&Query=".$term."&Sources=".$type."&".$type.".Count=".$count."&JsonType=raw");
curl_setopt ($chCURLOPT_RETURNTRANSFER1); 
curl_setopt ($chCURLOPT_CONNECTTIMEOUT$timeout); 
$search curl_exec($ch); 
curl_close($ch);
$Response json_decode($search,true);
    foreach(
$Response[SearchResponse][$type][Results] as $item){
    echo(
"        
                            <div class='style4' style='margin-left:1em; margin-right:1em'>"
.$item[Title]."</div>
                            <div class='style6' style='margin-left:1em; margin-right:1em'>"
.$item[Description]."</div>
                            <div class='style4' style='margin-left:1em; margin-right:1em'><a href='"
.$item[Url]."' target='_blank'>".$item[Url]."</a></div>
                        <br>
                    "
);
    }echo 
$Response;
?>
__________________
Sleeping Troll, EMUSE, Mind Expansion...Truly serendipity!

Last edited by Sleeping Troll; 07-31-2010 at 12:47 AM..
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need to use a var to reference array
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.64622 seconds with 12 queries