Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Alphabetical Search Menu for your vBulletin page
veenuisthebest's Avatar
veenuisthebest
Join Date: Mar 2008
Posts: 1,416

100% BCA, 33.33% CA

India
Show Printable Version Email this Page Subscription
veenuisthebest veenuisthebest is offline 08-11-2008, 10:00 PM

This tutorial will help you make an alphabetical search menu similar to what we see in memberlist.php

I had been looking for this for quite some time, opened a thread too but no help. Now, after some little programming homework I find it quite easy. Hope few of you find this useful.
  1. Assuming you have intermediate knowledge of HTML and PHP.
  2. Its hard for me to understand how this is done in memberlist.php. But this is the most easy way.
  3. Do follow the comments in code.
  4. I am not a coder.


1. First, we create a template for our product titled alphamenu and copy this code into it.

HTML Code:
<table class="tborder" cellpadding="6" cellspacing="1" border="0" width="100%" align="center">

<tr align="center">

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=A">A</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=B">B</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=C">C</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=D">D</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=E">E</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=F">F</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=G">G</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=H">H</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=I">I</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=J">J</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=K">K</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=L">L</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=M">M</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=N">N</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=O">O</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=P">P</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=Q">Q</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=R">R</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=S">S</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=T">T</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=U">U</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=V">V</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=W">W</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=X">X</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=Y">Y</a></td>

<td class="alt2" width="3%"><a href="page.php?do=alphasearch&amp;ltr=Z">Z</a></td>

</tr>
</table>
2. Then in our custom vbulletin page.php, we create a subpage called alphasearch and copy the below code into it. Ofcourse, this would require editing according to your needs, so read the comments carefully.


PHP Code:
//******* ALPHA SEARCH MENU*******
if ($_REQUEST['do'] == 'alphasearch'//Creating sub-page
{

if(empty(
$_REQUEST['ltr'])
{
    eval(
standard_error(fetch_error('error_invalidurl'))); // Error phrase for invalid url
}

$vbulletin->input->clean_gpc('g''ltr'TYPE_STR);
$letter=$db->escape_string($vbulletin->GPC['ltr']);

//****Beginning Page Navigation ***//    
    // Default page variables
    
$perpage $vbulletin->input->clean_gpc('r''perpage'TYPE_UINT);
    
$pagenumber $vbulletin->input->clean_gpc('r''pagenumber'TYPE_UINT);
    
// Count all log entries
    
$itemcount $db->query_first("
        SELECT COUNT(`uid`) AS `itemcount`
        FROM `" 
TABLE_PREFIX "mytable` WHERE colname LIKE '" $letter "%'"); //Change colname to actual column name in table that you want to search in.
        
if ($itemcount['itemcount'] == 0) { // Show if recordset empty
$emptysearch=true// With this, you can easily create a condition in the template to show NO ITEMS message
// Show if recordset empty        
        
   // Make sure all these variables are cool
    
sanitize_pageresults($itemcount['itemcount'], $pagenumber$perpage108); //Change 8 to as many records you want to show per page
    // Default lower and upper limit variables
    
$limitlower = ($pagenumber 1) * $perpage 1;
    
$limitupper $pagenumber $perpage;
    if (
$limitupper $itemcount['itemcount'])
    {
        
// Too many for upper limit
        
$limitupper $itemcount['itemcount'];
        if (
$limitlower $itemcount['itemcount'])
        {
            
// Too many for lower limit
            
$limitlower $itemcount['itemcount'] - $perpage;
        }
    }
    if (
$limitlower <= 0)
    {
        
// Can't have negative or null lower limit
        
$limitlower 1;
    }

eval(
'$alphamenu .= "' fetch_template('alphamenu') . '";'); //Use this line of code to show alphamenu in any sub-page you want. Then simply use $alphamenu variable in the associated template.

$query_Searchltr=$db->query_read("SELECT * from " TABLE_PREFIX "mytable WHERE colname LIKE '" $letter "%' LIMIT " . ($limitlower 1) . ", $perpage"); //Change colname to the same column name you had set in the above count query

while ($search_result $db->fetch_array($query_Searchltr))
{
$row_id=$search_result['uid'];
$row_name=$search_result['name'];
$row_class=$search_result['class'];
// and so on...
}
   
// Finally construct the page nav
$pagenav construct_page_nav($pagenumber$perpage$itemcount['itemcount'], 'page.php?do=alphasearch' $vbulletin->session->vars['sessionurl'] . '&amp;ltr=' $letter);  
//****End Page Navigation******//

$navbits construct_navbits($navbits);
eval(
'$navbar = "' fetch_template('navbar') . '";');
eval(
'print_output("' fetch_template('mysearchbits') . '");'); //The main output prints on mysearchbits template, so create it and use variables defined within the while loop above for results
$db->free_result($query_Searchltr);
}
//*******END ALPHA SEARCH MENU******* 
Now, as said earlier in comments, simply use this line in any sub-page and put $alphamenu in the associated template. This would show the menu.

PHP Code:
eval('$alphamenu .= "' fetch_template('alphamenu') . '";'); 


By: http://tech6.com
Reply With Quote
  #2  
Old 09-21-2008, 06:40 PM
jose22 jose22 is offline
 
Join Date: Jul 2008
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

do not understand that part of -> So, in our usual vbulletin page.php, we will create a sub-called alphasearch and copy the code below for this. Sure, it would require editing to suit your needs, so read the comments.
and where it can help? pa of creating for instance in the cinema section of my forum?
Reply With Quote
  #3  
Old 01-10-2009, 08:46 PM
vietfancy's Avatar
vietfancy vietfancy is offline
 
Join Date: Feb 2005
Posts: 278
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

very useful. Thanks
Reply With Quote
  #4  
Old 01-15-2009, 12:01 PM
Shadab's Avatar
Shadab Shadab is offline
 
Join Date: Apr 2007
Location: Bhopal
Posts: 39
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
if( isset($_GET['ltr']) )
{
    
$letter $_GET['ltr'];
}

// <snip>

$itemcount $db->query_first("
    SELECT COUNT(`uid`) AS `itemcount`
    FROM `" 
TABLE_PREFIX "mytable`
    WHERE colname LIKE '" 
$letter "%'"); 

$letter is assigned the value from $_GET['ltr']
and then directly used in the DB query without sanitizing it.

Is that safe ?
Reply With Quote
  #5  
Old 01-15-2009, 02:14 PM
veenuisthebest's Avatar
veenuisthebest veenuisthebest is offline
 
Join Date: Mar 2008
Location: India
Posts: 1,416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have edited the code. I think its safe now.
Reply With Quote
  #6  
Old 03-30-2009, 09:35 AM
vbplusme vbplusme is offline
 
Join Date: Sep 2008
Location: CyberSpace
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Caution: This "Tutorial" does NOT describe a WORKING mod and does not work as written. It is COMPLETELY based on a "theoretical" model and is completely worthless as a realtime MOD that just needs to be "tweaked". Not sure what the author was thinking when he called it a tutorial?
Reply With Quote
  #7  
Old 03-30-2009, 11:23 AM
veenuisthebest's Avatar
veenuisthebest veenuisthebest is offline
 
Join Date: Mar 2008
Location: India
Posts: 1,416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by vbplusme View Post
Caution: This "Tutorial" does NOT describe a WORKING mod and does not work as written. It is COMPLETELY based on a "theoretical" model and is completely worthless as a realtime MOD that just needs to be "tweaked". Not sure what the author was thinking when he called it a tutorial?
ehm.. that is what an article is. ROFL!

Quote:
Originally Posted by 1st point of article
# Assuming you have intermediate knowledge of HTML and PHP.
Reply With Quote
  #8  
Old 04-04-2009, 03:06 AM
Jasem's Avatar
Jasem Jasem is offline
 
Join Date: Feb 2006
Location: www.menokia.com
Posts: 594
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thank you!
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 06:46 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07602 seconds
  • Memory Usage 2,325KB
  • Queries Executed 23 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_html
  • (3)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (7)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete