dusean Posted January 6, 2009 Share Posted January 6, 2009 hey guys ...topic´s subject tells you what I am looking after .. I made query for my forum to display forums attachment by forumid .... so suppose a user wanna see post from one particular category .. he click there and see all the posts from the category he choose . my code look like this <?php /** * VBulletin Torrent Tracker 3 PHP v1.1 SVN * Coded by Toolmanwill **/ // ####################### SET PHP ENVIRONMENT ########################### error_reporting(E_ALL & ~E_NOTICE); // #################### DEFINE IMPORTANT CONSTANTS ####################### define('NO_REGISTER_GLOBALS', 1); define('THIS_SCRIPT', 'torrents'); // ################### PRE-CACHE TEMPLATES AND DATA ###################### // get special phrase groups $phrasegroups = array('global','search', 'forumdisplay'); // get special data templates from the datastore $specialtemplates = array(); // pre-cache templates used by specific actions $actiontemplates = array(); // pre-cache templates used by all actions $globaltemplates = array( 'VBTT_Torrents_Page', 'VBTT_Torrents_Bits', 'forumrules' ); // pre-cache templates used by specific actions $actiontemplates = array(); // ######################### REQUIRE BACK-END ############################ require_once('./global.php'); require_once(DIR . '/includes/functions_bigthree.php'); require_once(DIR . '/includes/class_postbit.php'); require_once (DIR.'/includes/functions_search.php'); require_once(DIR . '/includes/functions_misc.php'); function html_option($value, $content, $selected_value) { return sprintf('<option%s value="%d">%s</option>', $value == $selected_value ? " selected" : "", $value, $content); } // ####################################################################### // ######################## START MAIN SCRIPT ############################ // ####################################################################### $perpage = $vbulletin->options['vbtt_torrents_per_page']; $exclude_forums = '0'; $forumid = intval($_REQUEST['f']); $c = $db->query("SELECT userid, username FROM " . TABLE_PREFIX . "user"); $users = array(); while ($d= $db->fetch_array($c)) { $users[$d['userid']] = $d['username'] ; } $f = $db->query("SELECT forumid , title , parentid FROM ".TABLE_PREFIX." forum "); $forum = array(); while ($g = $db->fetch_array($f)) { $forum[$g['userid']] = $g['username'] ; } $title = $forum[$GLOBALS[forumid]]; if ($perpage == '') $perpage = 30; // default value if ($_REQUEST['sort']) { $sort = (string) strtolower($_REQUEST['sort']); $valid_sort = array( 'filename', 'size', 'dateline', 'seeders', 'leechers', 'forumid', 'completed', 'dlspeed', 'ulspeed' ); if (!in_array($sort, $valid_sort)) { $sort = 'dateline'; } } else { $sort = 'dateline' ; } if ($_REQUEST['order']) { $order = (string) strtolower($_REQUEST['order']); $valid_order = array( 'desc', 'asc', 'forumid' ); if (!in_array($order, $valid_order)) { $order = 'desc'; } } else { $order = 'desc'; } if ($_REQUEST['query'] != '') { $query = sanitize_word_for_sql($_REQUEST['query']) ; $search .= "AND SUBSTRING_INDEX(filename, '.torrent',1) LIKE '%".$query."%'"; } if ($_REQUEST['mode']) { $mode = (string) strtolower($_REQUEST['mode']); $valid_mode = array( 'orphan', 'latest', 'top', ); if (!in_array($mode, $valid_mode)) { $mode = ''; } else { if ($mode == 'orphan') { $search .= "AND leechers > 0 AND seeders = 0"; } else if ($mode == 'latest') { $search_comp = "dateline DESC,"; } else if ($mode == 'top') { $search_comp = "seeders + leechers DESC,"; } } } else { $mode = ''; } [b]if (1) // this is the main code which contains the category query { $forums1 = $db->query("SELECT forumid , title , parentid FROM ".TABLE_PREFIX." forum "); $forums = array(); while ($forum = $db->fetch_array($forums1)) $forums[$forum['forumid']] = $forum; function enable_forum($forum_id, &$forums) { if (!isset($forums[$forum_id]) || isset($forums[$forum_id]['show'])) return; $forums[$forum_id]['show'] = true; enable_forum($forums[$forum_id]['parentid'], $forums); } function do_forum($forum_id, $forums, $indent) { $d = ''; foreach ($forums as $forum) { if ($forum['parentid'] != $forum_id || !isset($forum['show'])) continue; $d .= html_option($forum['forumid'], str_repeat(' ', $indent) . $forum['title'], $GLOBALS['forumid']); $d .= do_forum($forum['forumid'], $forums, $indent + 1); } return $d; } $categories = $db->query("SELECT forumid FROM ".TABLE_PREFIX." attachment"); while ($category = $db->fetch_array($categories)) { enable_forum($category['forumid'], $forums); } $categorybits = '<option value="">All</option>' . do_forum(-1, $forums, 0); } else { $categories = $db->query("SELECT forumid FROM ".TABLE_PREFIX." attachment"); $categorybits = '<option value="">All</option>'; while ($category = $db->fetch_array($categories)) { $categorybits = html_option($category['forumid'], $category['title'], $forumid); } } [/b] $result = $db->query_first(" SELECT COUNT(*) AS count FROM ".TABLE_PREFIX."attachment WHERE info_hash != '' ".$search); $pagenumber = $_REQUEST['page'] > 0 ? (int) $_REQUEST['page'] : 1; $rows = $result['count']; $pages = ceil($rows / $perpage); if ($pagenumber < 1) { $pagenumber = 1; } else if ($pagenumber > $rows) { $pagenumber = $rows; } $minlimit = ($pagenumber - 1) * $perpage+1; $maxlimit = ($pagenumber) * $perpage; if ($maxlimit > $rows) { $maxlimit = $rows; $minlimit = $minlimit > $rows ? $rows-$perpage : $minlimit; } $minlimit = $minlimit <= 0 ? 1 : $minlimit; $pagenav = construct_page_nav($pagenumber, $perpage, $rows, "torrents.php?$session[sessionurl]pp=$perpage<r=$selectedletter&sort=$sort&order=$order&mode=$mode&query=$query&f=$forumid",'' ); $searchquery = "pp=$perpage<r=$selectedletter&order=$order&mode=$mode&query=$query&$f=$category[forumid]"; // ############################################################################# // start search timer $searchstart = microtime(); $attachment = $db->query_read(" SELECT attachment.info_hash, attachment.attachmentid,attachment.forumid, attachment.userid, attachment.filename, attachment.size , attachment.dateline, attachment.postid, attachment.seeders, attachment.leechers, attachment.completed, post.threadid, post.title FROM " . TABLE_PREFIX . "attachment LEFT JOIN " . TABLE_PREFIX . "post ON attachment.postid = post.postid WHERE info_hash != '' ".$search." ORDER BY ".$search_comp." $sort $order LIMIT " . ($minlimit-1) . ", $perpage "); $alt = 1; while ($attach = $db->fetch_array($attachment)) { $alt = ($alt==1)?($alt+1)$alt-1); $attach['alt'] = $alt; $attach['title'] = preg_replace("/\.torrent/","",$attach['title']); $temp = substr($attach["title"],0,$vbulletin->options['vbtt_max_length']); if ($temp!=$attach['title']) $temp.='...'; $attach['title'] = $temp; $attach['dateline'] = gmdate('Y-m-d H:s', $attach['dateline']); $attach['size'] = mksize($attach['size']); $attach['leechers'] = "<font color=\"" . (($attach['leechers']==0)?"red":"blue") . "\">" . $attach['leechers'] . "</font>"; $attach['seeders'] = "<font color=\"" . (($attach['seeders']==0)?"red":"green") . "\">" . $attach['seeders'] . "</font>"; $uspeeds = $db->query("SELECT SUM(ulspeed) as ulspeedtot ,SUM(dlspeed) as dlspeedtot FROM ". TABLE_PREFIX ."peers WHERE info_hash = '".$attach['info_hash']."'"); $uspeed = $db->fetch_array($uspeeds); $ulspeedtot = $uspeed['ulspeedtot']; $dlspeedtot = $uspeed['dlspeedtot']; $username = $users[$attach[userid]]; if ($ulspeedtot =="0") $attach[ulspeed] = "<font color=red>".mksize($ulspeedtot, 1, true)."/s"."</font>"; else $attach[ulspeed] = "<font color=green>".mksize($ulspeedtot, 1, true)."/s"."</font>"; if ($dlspeedtot =="0") $attach[dlspeed] = "<font color=red>".mksize($dlspeedtot, 1, true)."/s"."</font>"; else $attach[dlspeed] = "<font color=blue>".mksize($dlspeedtot , 1, true)."/s"."</font>"; eval('$torrents_bit .= "' . fetch_template('VBTT_Torrents_Bits') . '";'); } // end search timer $searchtime = vb_number_format(fetch_microtime_difference($searchstart), 2); // ############################################################################# // show forum rules construct_forum_rules($forum, $forumperms); // ############################################################################# // draw navbar $navbits = array("torrents.php?$session[sessionurl]" => "Torrents"); $navbits = construct_navbits($navbits); eval('$navbar = "' . fetch_template('navbar') . '";'); // ############################################################################# // output page eval('print_output("' . fetch_template('VBTT_Torrents_Page') . '");'); ?> site adress is www.dhbworld.com/torrents.php Link to comment https://forums.phpfreaks.com/topic/139679-my-serach-query-is-not-working-help-please/ Share on other sites More sharing options...
gevans Posted January 6, 2009 Share Posted January 6, 2009 That is a lot of code you have there to just list like that, also you're using Vbulletin, don't you feel it would be better to ask Vbulletin about this? Link to comment https://forums.phpfreaks.com/topic/139679-my-serach-query-is-not-working-help-please/#findComment-730799 Share on other sites More sharing options...
dusean Posted January 6, 2009 Author Share Posted January 6, 2009 they didn´t helped me with this so that´s why I thought to ask here Link to comment https://forums.phpfreaks.com/topic/139679-my-serach-query-is-not-working-help-please/#findComment-730801 Share on other sites More sharing options...
dusean Posted January 6, 2009 Author Share Posted January 6, 2009 this is the main script for cateegory search if (1) // this is the main code which contains the category query { $forums1 = $db->query("SELECT forumid , title , parentid FROM ".TABLE_PREFIX." forum "); $forums = array(); while ($forum = $db->fetch_array($forums1)) $forums[$forum['forumid']] = $forum; function enable_forum($forum_id, &$forums) { if (!isset($forums[$forum_id]) || isset($forums[$forum_id]['show'])) return; $forums[$forum_id]['show'] = true; enable_forum($forums[$forum_id]['parentid'], $forums); } function do_forum($forum_id, $forums, $indent) { $d = ''; foreach ($forums as $forum) { if ($forum['parentid'] != $forum_id || !isset($forum['show'])) continue; $d .= html_option($forum['forumid'], str_repeat(' ', $indent) . $forum['title'], $GLOBALS['forumid']); $d .= do_forum($forum['forumid'], $forums, $indent + 1); } return $d; } $categories = $db->query("SELECT forumid FROM ".TABLE_PREFIX." attachment"); while ($category = $db->fetch_array($categories)) { enable_forum($category['forumid'], $forums); } $categorybits = '<option value="">All</option>' . do_forum(-1, $forums, 0); } else { $categories = $db->query("SELECT forumid FROM ".TABLE_PREFIX." attachment"); $categorybits = '<option value="">All</option>'; while ($category = $db->fetch_array($categories)) { $categorybits = html_option($category['forumid'], $category['title'], $forumid); } } Link to comment https://forums.phpfreaks.com/topic/139679-my-serach-query-is-not-working-help-please/#findComment-730804 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.