HI I have a site the searches rapidshare etc its in my sig, what I would like to do is show adds between the search results on the data base search, its just a case of making the add show up at intervals of say every 8 rows in a table is this as easy as it sounds. Many Thanks Steve
Ok so ive had a go myself with no success. below is the code for the results echo " <table><tr><td width=\"22\"><img src=\"images/$img.png\"></td><td> <a href=\"download.php?id=$link\" title=\"$fullname\" target=\"_blank\"><b>" . $name . "</b></a><br /><font color=\"#969696\"><b>Added:</b> $date | <b>Size:</b> $size | </font><A href=\"javascript:void();\" onclick=\"ShowContent('desc$i');\"><font color=\"#969696\">Rapidshare search Description</font></a> </td></tr> <tr><td></td><td class=\"smallText\"><div style=\"display:none;\" id=\"desc$i\">$description<A href=\"javascript:void();\" onclick=\"HideContent('desc$i');\"><i> - Close</i></a></div></td></tr> </table><br /> "; PHP: If i put the ad after this code it shows after every result as I would expect, so I tried to be clever and duplicate the code above into several table rows like result result result ad Still no joy as it seems to duplicate the results of the search for each table row Help
There must be some kind of loop that wraps that echo-code. It could be a "foreach" or "for". Without full code (with the loop), i can't tell the code precisely, but if you know a little bit about PHP, it could be fairly easy. Modify the loop into like this <?php $x = 0;// add this foreach ($something as $some) { $x++;// add this echo $the_long_code_here; if ($x % 5 == 0) {// add this echo $put_your_ads_code_here;// add this }// add this } ?> PHP: Or this ("for" style) <?php $x = 0;// add this for ($a=0;$a<=$max;$a++) { $x++;// add this echo $the_long_code_here; if ($x % 5 == 0) {// add this echo $put_your_ads_code_here;// add this }// add this } ?> PHP:
Ok so I changed to $results ="<table><tr><td width=\"22\"><img src=\"images/$img.png\"></td><td> <a href=\"download.php?id=$link\" title=\"$fullname\" target=\"_blank\"><b>" . $name . "</b></a><br /><font color=\"#969696\"><b>Added:</b> $date | <b>Size:</b> $size | </font><A href=\"javascript:void();\" onclick=\"ShowContent('desc$i');\"><font color=\"#969696\">Rapidshare search Description</font></a> </td></tr> <tr><td></td><td class=\"smallText\"><div style=\"display:none;\" id=\"desc$i\">$description<A href=\"javascript:void();\" onclick=\"HideContent('desc$i');\"><i> - Close</i></a></div></td></tr> </table><br />"; $gads ="ads here"; $x = 0;// add this for ($a=0;$a<=$max;$a++) { $x++;// add this echo $results; if ($x % 5 == 0) {// add this echo $gads;// add this }// add this } PHP: It sort of worked but still not right it puts the ads in every 5 rows but each set of rows have 5 results the same. result1 result1 result1 result1 result1 ad result2 result2 result2 result2 result2 I cant seem to find the code that is making this happen this is everything in the php file <?$fullname = $name; if (strlen($name) >= 70) $name = substr($name, 0, 110) . ".."; // Shorten name if letter count is > than specified number. $img = "unkown"; if ($filetype == "rar") $img = "rar"; if ($filetype == "avi") $img = "mov"; if ($filetype == "mpeg") $img = "mov"; if ($filetype == "mpg") $img = "mov"; if ($filetype == "mp3") $img = "mp3"; if ($filetype == "wma") $img = "wm"; if ($filetype == "wmv") $img = "wm"; if ($filetype == "zip") $img = "zip"; if ($filetype == "txt") $img = "txt"; if ($filetype == "exe") $img = "exe"; if ($filetype == "pdf") $img = "pdf"; if ($filetype == "swf") $img = "swf"; if ($filetype == "fla") $img = "swf"; if ($filetype == "psd") $img = "psd"; if ($filetype == "doc") $img = "doc"; echo " <table><tr><td width=\"22\"><img src=\"images/$img.png\"></td><td> <a href=\"download.php?id=$link\" title=\"$fullname\"><b>" . $name . "</b></a><br /><font color=\"#969696\"><b>Added:</b> $date | <b>Size:</b> $size | </font><A href=\"javascript:void();\" onclick=\"ShowContent('desc$i');\"><font color=\"#969696\">View Description</font></a> </td></tr> <tr><td></td><td class=\"smallText\"><div style=\"display:none;\" id=\"desc$i\">$description<A href=\"javascript:void();\" onclick=\"HideContent('desc$i');\"><i> - Close</i></a></div></td></tr> </table><br /> "; ?> PHP: This is the functions.php that makes it work (I think) <? function fetchresults ($search, $source, $filetype, $page, $key, $history_amount) { $API = getapi (); $API = remoteapilimit ($API); $sort = strip_tags ($_GET[sort]); $source = strip_tags ($_GET[source]); $query = urlencode (strip_tags ($_GET[search])); $page = strip_tags ($_GET[page]); $filetype = strip_tags ($_GET[filetype]); if ($page < 1) { $page = '1'; } if (!is_numeric ($page)) { $page = '1'; } if ($source == '') { $source = 'all'; } if ($query == '') { exit ('No Query.'); } $found = '0'; if ($source == 'all') { if (!($res = @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+rapidshare&extension=' . $filetype . '&page=' . $page . '&sort=' . $sort))) { exit ('<error>Cannot get requested information.</error>'); ; } if (!($res = $res . @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+megaupload&extension=' . $filetype . '&page=' . $page . '&sort=' . $sort))) { exit ('<error>Cannot get requested information.</error>'); ; } if (!($res = $res . @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+megashares&extension=' . $filetype . '&page=' . $page . '&sort=' . $sort))) { exit ('<error>Cannot get requested information.</error>'); ; } if (!($res = $res . @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+badongo&extension=' . $filetype . '&page=' . $page . '&sort=' . $sort))) { exit ('<error>Cannot get requested information.</error>'); ; } if (!($res = $res . @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+filefront&extension=' . $filetype . '&page=' . $page . '&sort=' . $sort))) { exit ('<error>Cannot get requested information.</error>'); ; } if (!($res = $res . @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+savefile&extension=' . $filetype . '&page=' . $page . '&sort=' . $sort))) { exit ('<error>Cannot get requested information.</error>'); ; } } else { if (!($res = @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+' . $source . '&extension=' . $filetype . '&page=' . $page))) { exit ('<error>Cannot get requested information.</error>'); ; } } $max = explode ('<hitsTotal>', $res); $max = explode ('</hitsTotal>', $max[1]); $max = $max[0]; $max = floor ($max / 10); if (100 <= $max) { $max = '100'; } $i = 2; while ($i < 100) { $rsx = explode ('<hits', $res); $rsx = $rsx[$i]; $rs = explode ('<added>', $rsx); $rs = explode ('</added>', $rs[1]); $date = $rs[0]; $rs = explode ('<extension>', $rsx); $rs = explode ('</extension>', $rs[1]); $filetype = $rs[0]; $rs = explode ('<size>', $rsx); $rs = explode ('</size>', $rs[1]); $size = $rs[0]; $rs = explode ('<name>', $rsx); $rs = explode ('</name>', $rs[1]); $name = $rs[0]; $rs = explode ('<description>', $rsx); $rs = explode ('</description>', $rs[1]); $description = $rs[0]; if ($desc == '') { $desc = 'No description saved.'; } $rs = explode ('<address>', $rsx); $rs = explode ('</address>', $rs[1]); $link = $rs[0]; $link = str_replace ('http://', '', $link); $rs = explode ('/', $link); $link = $rs[1]; if ($name) { include 'includes/layout_list.php'; $found = '1'; } ++$i; } if ($found == '1') { writehistory ($search, $history_amount); } if ($found != '1') { echo '<center><b>Sorry, No results where found for that query.</b><br />Why not try again using a less specific words or phrases.</center>'; } } function getstats ($stats_name) { if (!($sql = mysql_query ('' . 'SELECT * FROM `stats` WHERE `Name` = \'' . $stats_name . '\''))) { exit ('<b>SQL ERROR:</b> 101, SQL Stats error.'); ; } if ($row = mysql_fetch_array ($sql)) { $Value = '' . $row['Value']; return $Value; } } function resetapikeys () { if (!($sql = mysql_query ('SELECT * FROM `api_keys`'))) { exit ('<b>SQL ERROR:</b> 100, Cannot update SQL Information.'); ; } while ($row = mysql_fetch_array ($sql)) { $ID = '' . $row['ID']; $date = '' . $row['Date']; $current_date = date (Y . '-' . m . '-' . d); if ($date != $current_date) { if (!(mysql_query ('' . 'UPDATE `api_keys` SET `Date`=\'' . $current_date . '\' WHERE ID = \'' . $ID . '\''))) { exit (mysql_error ()); ; } if (!(mysql_query ('' . 'UPDATE `api_keys` SET `Used`=\'0\' WHERE ID = \'' . $ID . '\''))) { exit (mysql_error ()); ; } continue; } } } function get_url ($url) { if (!($sql = mysql_query ('SELECT * FROM `general` WHERE `Name` = \'Get_Method\''))) { exit ('<b>SQL ERROR:</b> 101, SQL Stats error.'); ; } while ($row = mysql_fetch_array ($sql)) { $use = '' . $row['Value']; } if ($use == 'cURL') { $ch = curl_init (); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_URL, $url); $res = curl_exec ($ch); curl_close ($ch); } else { $res = @file_get_contents ($url); } return $res; } function remoteapilimit ($API) { $res = @get_url ('' . 'http://api.filestube.com/?key=' . $API . '&phrase=n'); $re = explode ('Query limit reached for key', $res); if ($re[1] != '') { if (!(mysql_query ('' . 'UPDATE `api_keys` SET `Used`=\'10000\' WHERE `Key`=\'' . $API . '\''))) { exit ('<b>SQL ERROR:</b> 100, Cannot update SQL Information.'); ; } return getapi (); } return $API; } function writehistory ($search, $svnm) { if (!($sql = mysql_query ('SELECT * FROM `general` WHERE `Name` = \'History_Limit\''))) { exit ('<b>SQL ERROR:</b> 102, Cannot write history.'); ; } while ($row = mysql_fetch_array ($sql)) { $history_limit = '' . $row['Value']; } if (!($sql = mysql_query ('' . 'SELECT * FROM `history` WHERE `Query`=\'' . $search . '\''))) { exit ('<b>SQL ERROR:</b> 102, Cannot write history.'); ; } while ($row = mysql_fetch_array ($sql)) { $ID = '' . $row['ID']; } if ($ID == '') { mysql_query ('' . 'INSERT INTO history (Query) values (\'' . $search . '\')'); } if (!($sql = mysql_query ('SELECT * FROM `history` ORDER BY `ID` ASC LIMIT 1'))) { exit ('<b>SQL ERROR:</b> 102, Cannot write history.'); ; } while ($row = mysql_fetch_array ($sql)) { $first_id = '' . $row['ID']; } if (!($sql = mysql_query ('SELECT * FROM `history`'))) { exit ('<b>SQL ERROR:</b> 102, Cannot write history.'); ; } $return_amount = mysql_num_rows ($sql); if ($history_limit <= $return_amount) { if (!(mysql_query ('' . 'DELETE FROM history WHERE ID=\'' . $first_id . '\''))) { exit (mysql_error ()); ; } } } function increasenum ($stats_name) { $Value = getstats ($stats_name); $Value = $Value + 1; if (!(mysql_query ('' . 'UPDATE `stats` SET `Value`=\'' . $Value . '\' WHERE Name = \'' . $stats_name . '\''))) { exit (mysql_error ()); ; } } function downloadlink ($d_id) { $res = @get_url ('' . 'http://www.filestube.com/' . $d_id . '/go.html'); $re = explode ('<iframe', $res); $re = explode ('src="', $re[1]); $re = explode ('"', $re[1]); $url = $re[0]; return $url; } function createbar ($content, $width) { echo '' . ' <table width="' . $width . '" border="0" cellpadding="0" height="14"><tr> <td width="15"><img src="images/bar_l.jpg"></td> <td style="background-image: url(images/bar.jpg);" class="barText">' . $content . '</td> <td width="15"><img src="images/bar_r.jpg"></td> </tr></table> '; } function getapi () { resetapikeys (); if (!($sql = mysql_query ('SELECT * FROM `api_keys` WHERE `Used` <= `Limit`'))) { exit ('<b>SQL ERROR:</b> 103, Cannot update SQL Information.'); ; } while ($row = mysql_fetch_array ($sql)) { $ID = '' . $row['ID']; $API = '' . $row['Key']; $used = '' . $row['Used']; $limit = '' . $row['Limit']; $new_used = $used + 1; if ($API != '') { if (!(mysql_query ('' . 'UPDATE `api_keys` SET `Used`=\'' . $new_used . '\' WHERE `ID`=\'' . $ID . '\''))) { exit ('<b>SQL ERROR:</b> 100, Cannot update SQL Information.'); ; } return $API; } exit ('<center><b>Sorry, there was a error. Please contact the site admin.</b></center>'); echo true; } } function xmlstr ($string, $start, $end) { $string = ' ' . $string; $ini = strpos ($string, $start); if ($ini == 0) { return ''; } $ini += strlen ($start); $len = strpos ($string, $end, $ini) - $ini; return substr ($string, $ini, $len); } function showhistory () { if (!($sql = mysql_query ('SELECT * FROM `general` WHERE `Name` = \'Search_Divider\''))) { exit ('<b>SQL ERROR:</b> 102, Cannot write history.'); ; } while ($row = mysql_fetch_array ($sql)) { $divider = '' . $row['Value']; } if (!($sql = mysql_query ('SELECT * FROM `general` WHERE `Name` = \'History_Limit\''))) { exit ('<b>SQL ERROR:</b> 102, Cannot write history.'); ; } while ($row = mysql_fetch_array ($sql)) { $history_limit = '' . $row['Value']; } if (!($sql = mysql_query ('' . 'SELECT * FROM `history` ORDER BY `ID` DESC LIMIT ' . $history_limit))) { exit ('<b>SQL ERROR:</b> 102, Cannot write history.'); ; } $return_amount = mysql_num_rows ($sql); while ($row = mysql_fetch_array ($sql)) { $search = '' . $row['Query']; echo '<a href="file_' . urlencode ($search) . '.html">' . urldecode ($search) . '</a>'; if ($i + 1 < $return_amount) { echo '' . ' ' . $divider . ' '; } ++$i; } } ?> PHP:
Which one is "includes/layout_list.php" ? Is it the first one? Assuming it is the first one, you can try this First, replace "fetchresults" function with this one function fetchresults ($search, $source, $filetype, $page, $key, $history_amount) { $API = getapi (); $API = remoteapilimit ($API); $sort = strip_tags ($_GET[sort]); $source = strip_tags ($_GET[source]); $query = urlencode (strip_tags ($_GET[search])); $page = strip_tags ($_GET[page]); $filetype = strip_tags ($_GET[filetype]); if ($page < 1) { $page = '1'; } if (!is_numeric ($page)) { $page = '1'; } if ($source == '') { $source = 'all'; } if ($query == '') { exit ('No Query.'); } $found = '0'; if ($source == 'all') { if (!($res = @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+rapidshare&extension=' . $filetype . '&page=' . $page . '&sort=' . $sort))) { exit ('<error>Cannot get requested information.</error>'); ; } if (!($res = $res . @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+megaupload&extension=' . $filetype . '&page=' . $page . '&sort=' . $sort))) { exit ('<error>Cannot get requested information.</error>'); ; } if (!($res = $res . @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+megashares&extension=' . $filetype . '&page=' . $page . '&sort=' . $sort))) { exit ('<error>Cannot get requested information.</error>'); ; } if (!($res = $res . @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+badongo&extension=' . $filetype . '&page=' . $page . '&sort=' . $sort))) { exit ('<error>Cannot get requested information.</error>'); ; } if (!($res = $res . @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+filefront&extension=' . $filetype . '&page=' . $page . '&sort=' . $sort))) { exit ('<error>Cannot get requested information.</error>'); ; } if (!($res = $res . @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+savefile&extension=' . $filetype . '&page=' . $page . '&sort=' . $sort))) { exit ('<error>Cannot get requested information.</error>'); ; } } else { if (!($res = @get_url ('http://api.filestube.com/?key=' . $API . '&phrase=' . $query . '+' . $source . '&extension=' . $filetype . '&page=' . $page))) { exit ('<error>Cannot get requested information.</error>'); ; } } $max = explode ('<hitsTotal>', $res); $max = explode ('</hitsTotal>', $max[1]); $max = $max[0]; $max = floor ($max / 10); if (100 <= $max) { $max = '100'; } $i = 2; $ads_count = 0;// this is what i add while ($i < 100) { $ads_count++;// this is what i add $show_ads = ($ads_count % 5 == 0);// this is what i add $rsx = explode ('<hits', $res); $rsx = $rsx[$i]; $rs = explode ('<added>', $rsx); $rs = explode ('</added>', $rs[1]); $date = $rs[0]; $rs = explode ('<extension>', $rsx); $rs = explode ('</extension>', $rs[1]); $filetype = $rs[0]; $rs = explode ('<size>', $rsx); $rs = explode ('</size>', $rs[1]); $size = $rs[0]; $rs = explode ('<name>', $rsx); $rs = explode ('</name>', $rs[1]); $name = $rs[0]; $rs = explode ('<description>', $rsx); $rs = explode ('</description>', $rs[1]); $description = $rs[0]; if ($desc == '') { $desc = 'No description saved.'; } $rs = explode ('<address>', $rsx); $rs = explode ('</address>', $rs[1]); $link = $rs[0]; $link = str_replace ('http://', '', $link); $rs = explode ('/', $link); $link = $rs[1]; if ($name) { include 'includes/layout_list.php'; $found = '1'; } ++$i; } if ($found == '1') { writehistory ($search, $history_amount); } if ($found != '1') { echo '<center><b>Sorry, No results where found for that query.</b><br />Why not try again using a less specific words or phrases.</center>'; } } PHP: And on layout_list.php, if ($show_ads) { echo $your_ga_ads_here; } echo " <table><tr><td width=\"22\"><img src=\"images/$img.png\"></td><td> <a href=\"download.php?id=$link\" title=\"$fullname\" target=\"_blank\"><b>" . $name . "</b></a><br /><font color=\"#969696\"><b>Added:</b> $date | <b>Size:</b> $size | </font><A href=\"javascript:void();\" onclick=\"ShowContent('desc$i');\"><font color=\"#969696\">Rapidshare search Description</font></a> </td></tr> <tr><td></td><td class=\"smallText\"><div style=\"display:none;\" id=\"desc$i\">$description<A href=\"javascript:void();\" onclick=\"HideContent('desc$i');\"><i> - Close</i></a></div></td></tr> </table><br /> "; PHP:
Thanks m8 it works like a charm one last problem sorry When i put the adsense code in I get a T string error, should the code be in an external file then called in instead This is what i Tried $gads ="<script type="text/javascript"><!-- google_ad_client = "pub-xxxxxxxxxxxxxxxxxxx"; /* 468x60, created 27/09/10 */ google_ad_slot = "0853740029"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>"; PHP:
Use single quote instead. Should work $gads = '<script type="text/javascript"><!-- google_ad_client = "pub-xxxxxxxxxxxxxxxxxxx"; /* 468x60, created 27/09/10 */ google_ad_slot = "0853740029"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>'; PHP: