adding other parameter to function

Posted by Ronnie Chester Lynwood on Stack Overflow See other posts from Stack Overflow or by Ronnie Chester Lynwood
Published on 2010-04-05T14:59:22Z Indexed on 2010/04/05 15:03 UTC
Read the original article Hit count: 291

Filed under:
|
|
|

hello. i got a function that listing downloads in a table with foreach. it's also lists searched term, search type.

public function fetchDownloads($displaySite=true) {
    $downloads = array();
    $sqlWhere = "";
    if(isset($this->q)) {
        if(strlen($this->q) <= $this->recents_length && !empty($this->q)) {
            $insertRecent = $this->processDataHook("insertRecent",$this->q);
            if($insertRecent) {
                if(!@mysql_query("INSERT INTO wcddl_recents (query) VALUES ('".$this->qSQL."')")) {
                @mysql_query("UPDATE wcddl_recents SET searches = searches+1 WHERE query = '".$this->qSQL."'");
                }
            }
        }
        if($this->search_type == "narrow") {
            $sqlWhere = " WHERE title LIKE '%".mysql_real_escape_string(str_replace(" ","%",$this->q))."%'";
        } elseif($this->search_type == "wide") {
            $qExp = explode(" ",$this->q);
            $sqlWhere = array();
            foreach($qExp as $fq)
                $sqlWhere[] = "title LIKE '%".mysql_real_escape_string($fq)."%'";
            $sqlWhere = implode(" OR ",$sqlWhere);
            $sqlWhere = " WHERE (".$sqlWhere.")";
        }
    }
    if(isset($this->type)) {
        if(!empty($sqlWhere)) {
        $sqlWhere .= " AND type = '".$this->typeSQL."'";
        } else {
        $sqlWhere = " WHERE type = '".$this->typeSQL."'";
        }
    }
    $sqlWhere = $this->processDataHook("fetchDownloadsSQLWhere",$sqlWhere);
    $this->maxPages = mysql_query("SELECT COUNT(*) FROM wcddl_downloads".$sqlWhere."");
    $this->maxPages = mysql_result($this->maxPages,0);
    $this->numRows = $this->maxPages;
    $this->maxPages = ceil($this->maxPages/$this->limit);

    $sqlMain = "SELECT id,sid,title,type,url,dat,views,rating FROM wcddl_downloads".$sqlWhere." ORDER BY ".(isset($this->sqlOrder) ? mysql_real_escape_string($this->sqlOrder) : "id DESC")." LIMIT ".$this->pg.",".$this->limit."";
    $sqlMain = $this->processDataHook("whileFetchDownloadsSQL",$sqlMain);
    $sqlMain = mysql_query($sqlMain);
    $this->processHook("whileFetchDownloads");
    while($row = mysql_fetch_assoc($sqlMain)) {
        if($displaySite) {
            $downloadSite = mysql_query("SELECT name as sname, url as surl, rating as srating FROM wcddl_sites WHERE id = '".$row['sid']."'");
            $downloadSite = mysql_fetch_assoc($downloadSite);
            $row = array_merge($row,$downloadSite);
        }
    $downloads_current = $this->mapit($row,array("stripslashes","strip_tags"));
    $downloads_current = $this->processDataHook("fetchDownloadsRow",$downloads_current);
    $downloads[] = $downloads_current;
    }
    $this->pageList = $this->getPages($this->page,$this->maxPages);
    $this->processHook("endFetchDownloads");
    return $downloads;
}

I want to add if $_REQUEST['site'] is set, order downloads by sname that catching from wcddl_sites.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql