something like this ?: <?php if ($_GET['s'] == '') { ?> <form method="get" style="margin-bottom:30px; margin-top:20px;"> <input type="text" name="s" size="30" /> <input type="submit" value="Search" /> </form> <?php } ?> <?php if ($_GET['s'] != '') { // connect to database if(@mysql_connect('localhost', 'user', 'pass')) { if(@mysql_select_db('yahooboss')) { $db_connected = true; } } // end_mysql_connect //Gather data and prepare query $thequery = urlencode($_GET['s']); $yhost = 'http://boss.yahooapis.com'; $apikey = 'YOUR KEY HERE'; $url = $yhost.'/ysearch/web/v1/'.$thequery.'?appid='.$apikey.'&format=xml&view=keyterms'; echo "<a href='$url'>$url</a><br>"; //Get the results $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); curl_close($ch); $results = new SimpleXmlElement($data, LIBXML_NOCDATA); //echo the results $related_cache = array(); foreach ($results->resultset_web->result as $theresult) { echo '<a href="'.$theresult->clickurl.'">'.$theresult->title.'</a><br/>'; echo $theresult->abstract.'<br/>'; echo '<small><i>'.$theresult->dispurl.'</i> </small> <br/>'; echo 'Related: '; if(isset($theresult->keyterms->terms->term)) { $rels = array(); foreach($theresult->keyterms->terms->term as $rel) { $rl_key = md5(strtolower($rel)); if(isset($related_cache[$rl_key])) continue; $rels[] = $rel; $related_cache[$rl_key] = $rel; } echo implode(', ', $rels); if(isset($db_connected) && !empty($rels)) { $query = "INSERT INTO related(`keyword`) VALUES ('"; $query .= implode("'), ('", $rels); $query .= "')"; mysql_query($query); } } echo '<br/><br/>'; } } ?> PHP:
That could do it, i'll pm you let me mock up the mysql insertion and see if it's what i wanted. From a quick glance it seems to be good!