vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Sort threads from sql (https://vborg.vbsupport.ru/showthread.php?t=198718)

webForum-dev 12-12-2008 07:47 PM

Sort threads from sql
 
Hello, I want to maintain the same sortorder in forumdisplay as default for paging and such (latest threads first), but I want to sort the threads returned by the database with php.

I thought I could use $sortfield for that, but I have tried this code

$sortfield = "thread.title";
$sqlsortfield = 'lastpost';
$handled = true;

booth in the forumdisplay_start and the forumdisplay_sort, but it just won't work.

Lynne 12-12-2008 09:42 PM

You set that in Forums & Moderators > Forum Manager > select the forum to edit > Default Sort Order/Default Sort Field

webForum-dev 12-13-2008 03:55 AM

ok, but I want to hook up a new sort of the result I get from the database. (so I dont want to change the way the results are sorted by the database)

my db-query looks something like this:
select a,b,c from threads where ... order by lastpost desc

I want to keep that sortorder, so that on each page I move through show me older posts as I go on.

but then on the listning (of that specific page) I want to order the results based on a new column that I have created in the database. This column tells if a thread is 'marked as solved' or not. I want to show booth the solved and not solved threads in the page as normal, but instead of just sorting it by lastpost desc, I want to sort it by solved, lastpost desc. So that the unsolved threads is shown first, and then the solved ones.

We did this modification without the plugin/hook-system (before 3.5) by modifying the forumdisplay.php, but now when we upgrade we need to convert this to plugin code, for easier upgrades of vbulletin.

Lynne 12-13-2008 04:03 AM

You need to use a hook that is called right before the query you are trying to modify. Like the hook forumdisplay_announcement_query is right above the announcement query, and forumdisplay_query_threadscount is right above the threascount query. The variables get emptied right before the query hooks:
PHP Code:

$hook_query_fields $hook_query_joins $hook_query_where '';
(
$hook vBulletinHook::fetch_hook('forumdisplay_query_threadscount')) ? eval($hook) : false



All times are GMT. The time now is 08:13 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00969 seconds
  • Memory Usage 1,715KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete