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
Writing a query in a database (Simple?)
Old 07-09-2009, 02:03 PM Writing a query in a database (Simple?)
Skilled Talker

Posts: 54
Trades: 0
Hello Webmasters. I need a little help with php.
I have a File Search engine and I want create a Search History with the new system (with own database). I have all ready but I need a Search History (history.php), I can easily use the old page and I just need one thing:

When users make a search they acess the page:
domain/index.php?q=Keyword&type=all&search=Search&stype=all

Keyword = Searched word.

I need that "Keyword" be added in a database: database_database in a Table: "history" with IDs: 1, 2, 3, 4 (+1 than last ID) and with the Keyword in the query.

How can I do it?

Here is some codes of my website:

index.php
PHP Code:
<?php
include "./functions.php";
include 
"./config.php";
require_once(
"includes/functions.php");


$info=array();
if(
file_exists('tagcloud.html'))
{
    
$tag_cloud=split("\n",trim(file_get_contents('tagcloud.html')));
    for(
$i=0;$i<$tag_cloud_count;$i++)
    {
        if(!
$tag_cloud[$i]) continue;
        if(
$i%2==0)    $info['tagcloud'].=$tag_cloud[$i];
        else                 
$info['tagcloud']=$tag_cloud[$i].$info['tagcloud'];
    }
    unset(
$tag_cloud);
}
if(!
count($_GET))
{
    
$info['total_links']=mysql_get_first_result("SELECT COUNT(*) FROM `v2links`");
    include 
"./templates/index.template.php";
    exit();
}
else
{
    
$stype="";
    if(
$_GET['stype']=='checked'$stype=" AND `fsize`<>''";
    
    if(!isset(
$_GET['type']) || $_GET['type']=="all"$fxtype="";
    else
    {
        if(
$_GET['type']>=&& $_GET['type']<=5$fxtype="AND type='".$_GET['type']."'";
        else 
$fxtype="";
    }
    
    
$kwd=mysql_real_escape_string($_GET['q']);
    
$info['keyword']=$kwd;
    
$info['total_results_count']=mysql_get_first_result("SELECT COUNT(*) FROM `v2links` WHERE  MATCH (caption) AGAINST ('$kwd')$stype $fxtype");

    
// navigation
    
if($_GET['start'] && is_numeric($_GET['start']))
    {
        
$start=$_GET['start'];
        
$start=((int)($start/$search_count))*$search_count;
    }
    else 
$start=0;
    
$info['curpage']=ceil(($start+1)/$search_count);
    
$info['total_pages']=ceil($info['total_results_count']/$search_count);
    
$navigation=array();
    
$navigation[]='<span class="navi navi_current"> -'.$info['curpage'].'- </span>'."\n";
    
$inc=$dec=$start;
    
$tcnt=0;
    for(
$i=0;$i<9;$i++)
    {
        
$inc+=$search_count;
        
$incp=ceil(($inc+1)/$search_count);
        
$dec-=$search_count;
        
$decp=ceil(($dec+1)/$search_count);
        if(
$inc<$info['total_results_count'])
        {
            
array_push($navigation,'<span class="navi"> <a href="./?q='.$_GET['q'].'&start='.$inc.'"&type='.$_GET['type'].'>'.$incp.'</a> </span> '."\n");
            
$tcnt++;
        }
        if(
$dec>=0)
        {
            
array_unshift($navigation,'<span class="navi"> <a href="./?q='.$_GET['q'].'&start='.$dec.'">'.$decp.'</a> </span> '."\n");
            
$tcnt++;
        }
        if(
$tcnt>=10) break;
    }
    
$navigation=join("",$navigation);
    
// end navigation    
    
    
$q="SELECT `url`,`caption`,`type`,`fsize`,MATCH (caption) AGAINST ('$kwd') as score,`source` FROM `v2links` WHERE  MATCH (caption) AGAINST ('$kwd')$stype $fxtype LIMIT $start,$search_count";
    
$query=mysql_query($q);
    
    
$num=0;
    
$info['results']=array();
    while(
$row=mysql_fetch_row($query))
    {
        
//print_r($row);
        
$info['results'][$num]['number']=$num+1;
        
$info['results'][$num]['url']=$row[0];
        
$info['results'][$num]['title']=$row[1];
        
$info['results'][$num]['type']=$row[2];
        if(
$row[3]) $info['results'][$num]['filesize']=", FileSize: ".$row[3]; //number_format($row[3],0,"."," ");
        
else $info['results'][$num]['filesize']="";
        if(
$row[5])
        {
            if(
strpos($row[5],"http://")!==false$info['results'][$num]['source']=" (<a href=\"".$row[5]."\" target=\"_blank\">source</a>)";
            else 
$info['results'][$num]['source']=" (<a href=\"http://".$row[5]."\" target=\"_blank\">source</a>)";
        }
        else                 
$info['results'][$num]['source']="";
        
$info['results'][$num]['relevance']=$row[4];

        
$substr=strtolower(substr($info['results'][$num]['url'],-20));
        foreach(
$icons as $key => $value)
        {
            
$iconlist=split(" ",$value);
            foreach(
$iconlist as $icon)
            {
                if(
strpos($substr,$icon)!==false)
                {
                    
$info['results'][$num]['icon']=$key;
                    break;
                }
            }
            if(
$info['results'][$num]['icon']) break;
        }
        if(
$key=="default"$key=$icons['default'];
        
$info['results'][$num]['icon']=$key;

        
$num++;
    }
    
    include 
"./templates/search_results.template.php";
    exit();
}
?>
functions.php
PHP Code:
<?php

function get_urls_by_kwd($gquery,$regexp,$type)
{
    print 
"=== $gquery === \n";
    
logstr("log-p.txt","=== $gquery === \n");
    for(
$g=0;$g<1000;$g+=100)
    {
        print 
"--- google page: $g --- \n";
        
logstr("log-p.txt","--- google page: $g --- \n");
        
$gurls=googleparse($gquery,100,$g);
        for(
$i=0;$i<count($gurls);$i++)
        {
            print 
"$i\t: ".$gurls[$i]."\n";
            
logstr("log-p.txt",memory_get_usage()."\n");
            
logstr("log-p.txt","$i\t: ".$gurls[$i]."\n");
            unset(
$links);
            
$links=array();
            
$links=parseforlinks("http://".$gurls[$i],$regexp);
            if(!
count($links)) break;
            
$linkcnt=0;
            
$dubcnt=0;
            for(
$j=0;$j<count($links);$j++)
            {
                
$caption='';
                if(
$type==1)
                {
                    
$words=$links[$j];
                    
preg_match("/rapidshare\.com\/files\/\d+\/(.+)/",$words,$match);
                    unset(
$words);
                    
$words=$match[1];
                    unset(
$match);
                    
$words=preg_split("/[_\.\-]/",$words);
                    
$lastword=array_pop($words);
                    if(
$lastword=="html"array_pop($words);
                    
$words=implode(" ",$words);
                    
$words=preg_replace("/\s{2,}/"," ",$words);
                    
$caption=mysql_real_escape_string($words);
                    unset(
$words);
                }
                
$url=mysql_real_escape_string($links[$j]);
                
$source=mysql_real_escape_string("http://".$gurls[$i]);

                
$query="INSERT INTO `v2links` VALUES(NULL,'$url','$caption','0000-00-00 00:00:00',0,'','$source','$type')";
                
//if(mysql_errno()) print mysql_error()."\n";
                //logstr("log-p.txt",$query);
                
mysql_query($query);
                if(
mysql_errno()==1062)
                {
                    if(
mysql_errno()) print mysql_error()."\n";
                    
$dubcnt++;
                    
$linkcnt++;
                }
                else
                {
                    print 
"good link! ($url) [text: $caption]\n";
                    
$linkcnt++;
                }
                if(!
file_exists("run-p.flag")) exit("run-p.flag was deleted\n");
                unset(
$caption);
                unset(
$url);
            }
            print 
"$linkcnt(t) :: $dubcnt(d)\n";
            
logstr("log-p.txt","$linkcnt(t) :: $dubcnt(d)\n");
        }
        unset(
$links);
    }
}


function 
sel($caption$query)
{
    require 
"./config.php";
    
$query mysql_query($query$mysql_link);
    if(
mysql_errno()) print mysql_error()."<br />\n";
    
$row mysql_fetch_array($query);
    
    
$key=@array_keys($row);
    
//$res="<b>$caption</b><BR>";
    
$res.="<table border=1><tr>";
    for(
$i=1$i<count($key); $i+=2)    $res.= "<td><b>".$key[$i]."</b></td>";
    
$res.= "</tr>";
    
    
$res.= "<tr>";
    for(
$i=0$i<count($key)/2$i++)
    {
        for(
$i=0$i<count($key)/2$i++)
        {
            if(!
$row[$i]) $row[$i] = "--";
            
$res.= "<td>".$row[$i]."</td>";
        }
    }
    
$res.= "</tr>";

    while(
$row mysql_fetch_array($query))
    {
        
$res.= "<tr>";
        for(
$i=0$i<count($key)/2$i++)
        {
            if(!
$row[$i]) $row[$i] = "--";
            
$res.= "<td>".$row[$i]."</td>";
        }
        
$res.= "</tr>";        
    }
    
$res.= "</tr></table>";    
    
mysql_free_result($query);
    
mysql_close($mysql_link);
    
$res.= "<BR>";
    print 
$res;
    return 
$res;
}
function 
googleparse($q,$num_res,$start)
{
    
$url="http://www.google.com/search?q=".urlencode($q)."&hl=en&&num=$num_res&start=$start&btnG=Google+Search&safe=on";
    
$ch curl_init();
    
curl_setopt($chCURLOPT_URL$url);
    
curl_setopt($chCURLOPT_TIMEOUT15);
    
curl_setopt($chCURLOPT_HEADER0);
    
curl_setopt($chCURLOPT_USERAGENT"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1");
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
$index=curl_exec($ch);
    
$error=curl_error($ch);    
    
curl_close($ch);
    
//print " [".strlen($index)."]\n";
    
    
preg_match_all("/href=\"http\:\/\/([^\"]+)\"\sclass=l/i",$index,$match);
    if(
$match[1]) return $match[1];
    else return 
false;
}

function 
parseforlinks($url,$regexp)
{
    
$ch curl_init();
    
curl_setopt($chCURLOPT_URL$url);
    
curl_setopt($chCURLOPT_TIMEOUT15);
    
curl_setopt($chCURLOPT_HEADER0);
    
curl_setopt($chCURLOPT_USERAGENT"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1");
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
$index=curl_exec($ch);
    
$error=curl_error($ch);    
    
curl_close($ch);
    
//print " [".strlen($index)."]\n";
    
    
preg_match_all($regexp,$index,$match);
    
//print_r($match);
    
if($match[0]) return $match[0];
    else return 
false;
}
function 
logstr($file,$str)
{
    
$f=fopen($file,"a");
    
fputs($f,$str);
    
fclose($f);
}
function 
getpage($url,$post=0,$referer=0)
{
    
$ch curl_init();
    
curl_setopt($chCURLOPT_URL$url);
    
curl_setopt($chCURLOPT_TIMEOUT15);
    if(
$post)
    {
        
curl_setopt($chCURLOPT_POST1);
        
curl_setopt($chCURLOPT_POSTFIELDS$post);
    }
    if(
$referercurl_setopt($chCURLOPT_REFERER$referer);    
    
    
curl_setopt($chCURLOPT_HEADER0);
    
curl_setopt($chCURLOPT_USERAGENT"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1");
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
$index=curl_exec($ch);
    
$error=curl_error($ch);    
    
curl_close($ch);

    if(
$index)    return $index;
    else                return 
false;
     
$found '1';
      }

    if (
$found == '1')
    {
      
writehistory ($search$history_amount);
}
function 
mysql_get_first_result($query)
{
    
$mq=mysql_query($query);
    
$mr=mysql_fetch_array($mq,MYSQL_NUM);
    
mysql_free_result($mq);
    return 
$mr[0];
}
function 
mysql_get_first_row($query)
{
    
$mq=mysql_query($query);
    
$mr=mysql_fetch_array($mq,MYSQL_NUM);
    
mysql_free_result($mq);
    return 
$mr;
}
?>
config.php (Edited)
PHP Code:
<?php
// search results preferences
$search_count=25;

// tag cloud preferences
$tag_cloud_count=20;

// ICONS SETTINGS
// $icons['filename'] = ".ext1 .ext2 .ext3";
$icons['multimedia.png']=".mp3 .avi .divx .mpeg";

// default icon filename, must be the last
$icons['default']="default.png";
// END OF ICONS SETTINGS


// DATABASE SETTINGS
$dbhost="EDITED";
$dbuser="EDITED";
$dbpass="EDITED";
$dbname="EDITED";
// END OF DATABASE SETTINGS

$mysql_link mysql_connect($dbhost,  $dbuser,  $dbpass) or exit("<br>Can't connect to MySQL!");
mysql_query("USE $dbname",  $mysql_link) or die ("<br>USE $dbname - error");
?>
history.php
PHP Code:
<?
require_once("includes/functions.php");
require_once(
"config.php");
?>
<html>
    <head>
    <link rel="shortcut icon" href="/favicon.ico">
    <title>Searching</title>


    </head>

    <body>
    <left><a href="http://www.domain.com">text</a></left>

<?
$sql
=mysql_query("SELECT `Value` FROM `general` WHERE `Name`='History_Limit'") or die (mysql_error());
while(
$row=mysql_fetch_array($sql)) $history_limit "$row[Value]";
?>
<?createBar
("Search History""100%")?>
<table width="100%" align="center" cellpadding="5"><tr><td align="center"><?showHistory();?></td></tr></table>
</td><td width="180" valign="top" align="right"></td></table>

<?createBar("<center>text</a><br>
All listed data are remotly requested. No responsibility can be taken for any misuse of files.</center>"
"100%");?>
</td></tr></table>

    </body>

</html>
index.template.php
PHP Code:
<html>
<head>
<title>text</title>
<meta name="keywords" content="Download, Downloads, Search Engine, File Search, Rapidshare Search, Megaupload Search, Badongo, SaveFile, FileFront, MegaShares" />
<script src="/mint/?js" type="text/javascript"></script>
<meta http-equiv=Content-Type content="text/html; charset=windows-1251" />
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,td,th {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #666666;
}
body {
    background-color: #FFFFFF;
}
a.tagcloudlink, a.tagcloudlink:visited {
    text-decoration: none;
    color: #006699;
}
.tagcloudblock{
    width: 400px;
}
a:link {
    color: #006699;
}
a:visited {
    color: #006699;
}
a:hover {
    color: #66CCFF;
}
a:active {
    color: #006699;
}
-->
</style>    
</head>
<body>
<br />
<center><img src="logo.gif"><br><br>
<div class="center">Text</b><br>
text<br>
text<br><br> 
<form name="search" method="_post" action="index.php">
    <input class="searchbox" type="text" name="q" />
    <select name="type">
        <option value="all" <? if($_GET['type']=='all') echo 'selected';?>>All</option>
        <option value="1" <? if($_GET['type']==1) echo 'selected';?>>Rapidshare</option>
        <option value="2" <? if($_GET['type']==2) echo 'selected';?>>Badongo</option>
        <option value="3" <? if($_GET['type']==3) echo 'selected';?>>Mediafire</option>
        <option value="4" <? if($_GET['type']==4) echo 'selected';?>>Sendspace</option>
        <option value="5" <? if($_GET['type']==5) echo 'selected';?>>4shared</option>
        <option value="6" <? if($_GET['type']==5) echo 'selected';?>>Megaupload</option>
    </select>
    <input type="submit" name="search" value="Search" /><br /><br />
    <input type="radio" name="stype" value="all" checked /> all files
    <input type="radio" name="stype" value="checked" /> checked files
</form>
<div class="info">
    We have <b><font color="#55771D"><? print number_format($info['total_links'],0,"."," "); ?></font></b> files in the database today
</div>
</div><br>
<br>
<div class="tagcloudblock">
<? echo $info['tagcloud']; ?><br>
</div>
<br><font size="1" color="#CCCCCC">Content Powered by Rapidshare, Badongo, MediaFire, Mediafire, Sendspace and 4Shared<br>
This search engine is in no way intended for illegal downloads.<br></font>

</body>
search_results.template.php
PHP Code:
<html>
<head>
<title>Rapidshare links search - Direct download links for rapidshare files</title>
<meta http-equiv=Content-Type content="text/html; charset=windows-1251" />
<meta http-equiv="cache-control" content="no-cache">
<style>
.info
{
    font-size: 14pt;
    color: gray;
}
.center { text-align: center; }
.searchbox
{
    width: 300px;
    border-style: groove;
}
.iteminfo
{
    font-size: 12pt;
    color gray:
}
.navi_current { font-weight: bold; }
.navi
{
    font-size: 16pt;
    color: brown;
}
a.navi,a.navi:visited
{
    text-decoration: none;
    color: brown;
}
a.navi:hover
{
    text-decoration: underline;
    color: brown;
}
td.item
{
    border-width: 1px;
    border-style: dotted;
    border-color: #666666;
    padding: 5px;
}
body {
    text-align: center;
    font-family: Arial,Verdana;
    font-size: 12px;
    }
a:link {
    color: #557221;
}
a:visited {
    color: #557221;
}
a:hover {
    color: #A1D54F;
}
a:active {
    color: #557221;
}
</style>
</head>
<body>
<div class="content"><img src="logohunter.gif"><br>
<br />
<font color="#666666">Free Search Engine for <b>Rapidshare, Badongo, Sendspace, MediaFire and 4Shared Files.</b><br>
Type what you are looking for on the box bellow, hit search and download it!<br>
Our database keep growing everyday, use "checked files" to refine your search.</font><br><br>
<form name="search" method="_post" action="index.php">
    <input class="searchbox" type="text" name="q" value="<? print $info['keyword']; ?>"/>
    <select name="type">
        <option value="all" <? if($_GET['type']=='all') echo 'selected';?>>All</option>
        <option value="1" <? if($_GET['type']==1) echo 'selected';?>>Rapidshare</option>
        <option value="2" <? if($_GET['type']==2) echo 'selected';?>>Badongo</option>
        <option value="3" <? if($_GET['type']==3) echo 'selected';?>>Mediafire</option>
        <option value="4" <? if($_GET['type']==4) echo 'selected';?>>Sendspace</option>
        <option value="5" <? if($_GET['type']==5) echo 'selected';?>>4shared</option>
    </select>
    <input type="submit" name="search" value="Search" /><br /><br />
    <input type="radio" name="stype" value="all" <? if(!isset($_GET['stype'])||$_GET['stype']=="all") print "checked";?> /> all files
    <input type="radio" name="stype" value="checked" <? if($_GET['stype']=="checked") print "checked";?> /> checked files
</form>
<?
if(count($info['results']))
print 
'<div class="info"><b>'.$info['total_results_count'].'</b> results found, page '.$info['curpage'].' from '.$info['total_pages'].'</div>';
?>
<p class="center">
<div class="adsense">
<!-- BEGIN SMOWTION TAG - 300x250 - peear: busquedas - DO NOT MODIFY -->
<script type="text/javascript"><!--
smowtion_size = "300x250";
smowtion_section = "635291";
//-->
</script>
<script type="text/javascript"
src="http://ads.smowtion.com/ad.js">
</script>
<!-- END SMOWTION TAG - 300x250 - peear: busquedas - DO NOT MODIFY -->
</div><br>
<table align="center">
<?
for($i=0;$i<count($info['results']);$i++)

{
    print
    
'<tr>
        <td class="item">
            <img src="./images/'
.$info['results'][$i]['icon'].'" width="48" height="48" border="0" alt="'.$info['results'][$i]['icon'].'" />
        </td>
        <td class="item">
            <table>
                <tr><td>'
.$info['results'][$i]['title'].'</a>'.$info['results'][$i]['filesize'].' '.$info['results'][$i]['source'].'</td></tr>
                <tr><td>
                    <a target="_blank" href="http://'
.$info['results'][$i]['url'].'">'.$info['results'][$i]['url'].'</a>
                </td></tr>
            </table>
        </td>
    </tr>
    '
."\n";
}

?>
</table>
<?
if(!count($info['results'])) print '<div class="info">No results found</div>';
else print 
'<br /><div class="center">'.$navigation."</div>";
?>
<br />
</p>
</body>
/includes/functions.php
PHP Code:
<?
  
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 ('-' '-' 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 ($chCURLOPT_RETURNTRANSFER1);
      
curl_setopt ($chCURLOPT_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 $return_amount)
      {
        echo 
'' ' ' $divider ' ';
      }

      ++
$i;
    }

  }
  
?>
Please Help me
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
.Fernando is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-11-2009, 06:10 AM Re: Writing a query in a database (Simple?)
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
did you write those yourself ?

im guessing not by the question
__________________

Please login or register to view this content. Registration is FREE
davidj is offline
Reply With Quote
View Public Profile
 
Old 07-11-2009, 08:44 AM Re: Writing a query in a database (Simple?)
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
in the page of the search, simply store it.
The table schema would be something like
Code:
create table history(
  historyId  integer auto_increment not null,
  keyword varchar(100) not null,
  searchDate timestamp default now(),
  primary key (historyId)
);
create unique index ui_history_keyword on history(keyword);
And simply add something like
Code:
$query="insert into history (keyword) values ('$keyword') on duplicate key update searchDate=now()";
This will record every keyword that your users send to the search, and if a keyword is already present, it will update the searchDate value to the last time it was used.
That way, you can fetch the 30 last searches easily.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-11-2009, 03:21 PM Re: Writing a query in a database (Simple?)
Skilled Talker

Posts: 54
Trades: 0
Quote:
Originally Posted by tripy View Post
in the page of the search, simply store it.
The table schema would be something like
Code:
create table history(
  historyId  integer auto_increment not null,
  keyword varchar(100) not null,
  searchDate timestamp default now(),
  primary key (historyId)
);
create unique index ui_history_keyword on history(keyword);
And simply add something like
Code:
$query="insert into history (keyword) values ('$keyword') on duplicate key update searchDate=now()";
This will record every keyword that your users send to the search, and if a keyword is already present, it will update the searchDate value to the last time it was used.
That way, you can fetch the 30 last searches easily.
Where in the code I put it? What file? Where?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
.Fernando is offline
Reply With Quote
View Public Profile
 
Old 07-12-2009, 08:59 AM Re: Writing a query in a database (Simple?)
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
You put it in the file where you do the search.

As for giving you exact details, I won't... I'm here to help peoples, not give away freelance time.
If you are not advanced enough to determine where it should go, ask a freelancer to help you, or learn some more.

This is something very basic, and should not pose much problem to anyone taking the time to try and learn.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 07-12-2009 at 09:02 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-13-2009, 10:07 PM Re: Writing a query in a database (Simple?)
konetch's Avatar
Ultra Talker

Posts: 258
Trades: 0
@.Fernando

tripy's right. You can't expect people to give you the code on these forums. Some may because they are trying to be helpful. If you're stuck, trying finding the answer by going through code, searching google, and reading tutorials. Not have people right code for you for free.

Good luck on your search fot the answer
__________________
Alex
konetch is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Writing a query in a database (Simple?)
 

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.27064 seconds with 12 queries