11
tzvook
Alphabetic Order as done @ Phpnuke
  • 2005/3/18 10:54

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


This is how Alpha order is done @ Phpnuke (for members lists) - means how rows are being counted and limited

I couldn't implement it - 3 hours of trying .... my head is exploading

http://www.hitwalker.nl/Snippet_library/index.php?cat_select=Phpnuke_related&show=Memberslist60_with_CNB_your_Account_



/************************************************************************/ 
/* PHP-NUKE: Web Portal System                                          */ 
/* ===========================                                          */ 
/*                                                                      */ 
/* Copyright (c) 2002 by Francisco Burzi                                */ 
/* http://phpnuke.org                                                   */ 
/*                                                                      */ 
/* =========================                                            */ 
/* Based on MyPHPortal Modified MembersList                             */ 
/*                                                                      */ 
/* This program is free software. You can redistribute it and/or modify */ 
/* it under the terms of the GNU General Public License as published by */ 
/* the Free Software Foundation; either version 2 of the License.       */ 
/* Modified by chatserv of http://www.nukeresources.com to work under   */ 
/* CNB Your Account                                                     */ 
/************************************************************************/ 

/* Some code taken from MemberList coded by Paul Joseph Thompson */ 
/* of www.slug.okstate.edu                                       */ 
/* In memoriam of Members List War ;)                            */ 

if (!eregi("modules.php"$PHP_SELF)) { 
    die (
"You can't access this file directly..."); 


require_once(
"mainfile.php"); 
$module_name basename(dirname(__FILE__)); 
get_lang($module_name); 

function 
alpha() { 
    
/* Creates the list of letters and makes them a link. */ 
    
global $sortby$module_name
        
$alphabet = array ("All""A","B","C","D","E","F","G","H","I","J","K","L","M"
                            
"N","O","P","Q","R","S","T","U","V","W","X","Y","Z","Other"); 
        
$num count($alphabet) - 1
        echo 
"
[ "
    
/* start of HTML */ 
        
$counter 0
        while (list(, 
$ltr) = each($alphabet)) { 
            echo 
"modules.php?name=$module_name&letter=$ltr&sortby=$sortby">$ltr"
            if ( 
$counter == round($num/2) ) { 
                echo 
" ]n
n[ "

            } elseif ( 
$counter != $num ) { 
                echo 
" | n"
            } 
            
$counter  
        } 
        echo 
" ]n
n
n"
;  // end of HTML 


function 
SortLinks($letter) {  // Makes order by links.. 
        
global $sortby$module_name
        if (
$letter == "front") { 
        
$letter "All"
    } 
        echo 
"n
n"// Start of HTML 
        
echo ""._SORTBY.[ "
        if (
$sortby == "username" OR !$sortby) { 
            echo 
""._MNICKNAME." | "
        } else { 
            echo 
"modules.php?name=$module_name&letter=$letter&sortby=username">"._MNICKNAME." | "
        } 
        if (
$sortby == "name") { 
            echo 
""._MREALNAME." | "
        } else { 
            echo 
"modules.php?name=$module_name&letter=$letter&sortby=name">"._MREALNAME." | "
        } 
        if (
$sortby == "femail") { 
            echo 
""._MEMAIL." | "
        } else { 
            echo 
"modules.php?name=$module_name&letter=$letter&sortby=femail">"._MEMAIL." | "
        } 
        if (
$sortby == "user_website") { 
            echo 
""._MURL." | "
        } else { 
            echo 
"modules.php?name=$module_name&letter=$letter&sortby=user_website">"._MURL.""
        } 
        echo 
]n
n"
// end of HTML 


include(
"header.php"); 
$pagesize 20

if (!isset(
$letter)) { $letter "A"; } 
if (!isset(
$sortby)) { $sortby "username"; } 
if (!isset(
$page)) { $page 1; } 

/* All of the code from here to around line 125 will be optimized a little later */ 
/* This is the header section that displays the last registered and who's logged in and whatnot */ 

$result sql_query("select username from ".$user_prefix."_users order by user_id DESC limit 0,1"$dbi); 
list(
$lastuser) = sql_fetch_row($result$dbi); 
echo 
"nnnn"
    
OpenTable(); 
        echo 
"
"._WELCOMETO.$sitename "._MEMBERSLIST."

n"
        echo 
""._GREETINGS.modules.php?name=Your_Account&op=userinfo&username=$lastuser">$lastusern
n
n"


        
$numrows sql_num_rows(sql_query("select user_id from ".$user_prefix."_users"$dbi), $dbi); 

        if (
is_user($user)) { 
            
$result2 sql_query("SELECT uname,guest FROM ".$prefix."_session where guest=0"$dbi); 
            
$member_online_num sql_num_rows($result2$dbi); 
        
$who_online ""._ONLINEREG.

"

            
$i 1
            while (
$session sql_fetch_array($result2$dbi)) { 
                if (isset(
$session["guest"]) and $session["guest"] == 0) { 
                    
$who_online .= "modules.php?name=Your_Account&op=userinfo&username=$session[uname]">$session[uname]n"
                    
$who_online .= ($i != $member_online_num " - " ""); 
                    
$i  
                } 
            } 
            echo 
"
"._WEHAVE.$numrows "._MREGISTERED.$member_online_numn"
            echo 
" "._MREGONLINE."


"

        
OpenTable2(); 
            echo 
"
$who_online
n"

        
CloseTable2(); 
        echo 
"

"

        } else { 
            echo 
"
"._WEHAVE.$numrows "._REGSOFAR."
n
n
n"

        } 

        
alpha(); 
        
SortLinks($letter); 

/* end of top memberlist section thingie */ 
/* This starts the beef...*/ 

        
$min $pagesize * ($page 1); // This is where we start our record set from 
        
$max $pagesize// This is how many rows to select 

        /* All my SQL stuff. DO NOT ALTER ANYTHING UNLESS YOU KNOW WHAT YOU ARE DOING */ 

/* This is a totaly crap code, any help to re-code this functions will be very appreciated */ 
/* Need to be database independent */ 

        
$count "SELECT COUNT(user_id) AS total FROM ".$user_prefix."_users "// Count all the users in the db.. 
        
$select "select user_id, name, username, femail, user_website from ".$user_prefix."_users "//select our data 
    
$where "where username != 'Anonymous' "
    if ( ( 
$letter != "Other" ) AND ( $letter != "All" ) ) {  // are we listing all or "other" ? 
            
$where .= "AND username like '".$letter."%' "// I guess we are not.. 
        
} else if ( ( $letter == "Other" ) AND ( $letter != "All" ) ) { // But other is numbers ? 
            
$where .= "AND username REGEXP "^[1-9]" "// REGEX :D, although i think its MySQL only 
                                                        // Will have to change this later. 
                                                        // if you know a better way to match only the first char 
                                                        // to be a number in uname, please change it and email 
                                                        // myphportal-developers@lists.sourceforge.net the correction 
                                                        // or goto http://sourceforge.net/projects/myphportal and post 
                                                        // your correction there. Thanks, Bjorn. 
        
} else { // or we are unknown or all.. 
            
$where .= ""// this is to get rid of anoying "undefinied variable" message 
        

        
$sort "order by $sortby"//sorty by ..... 
        
$limit " ASC LIMIT ".$min.", ".$max// we only want rows $min  to $max 
        /* due to how this works, i need the total number of users per 
        letter group, then we can hack of the ones we want to view */ 
        
$count_result sql_query($count.$where$dbi); 
        
$num_rows_per_order mysql_result($count_result,0,0); 

        
/* This is where we get our limit'd result set. */ 
        
$result sql_query($select.$where.$sort.$limit$dbi) or die(); // Now lets do it !! 

/* Crap code ends here */ 

        
echo "
"

        if ( 
$letter != "front" ) { 
            echo 
"1" border="0" cellspacing="1">n"
            echo 
"$bgcolor4" align="center">$textcolor2">"._NICKNAME."n"
            echo 
"$bgcolor4" align="center">$textcolor2">"._REALNAME."n"
            echo 
"$bgcolor4" align="center">$textcolor2">"._EMAIL."n"
            echo 
"$bgcolor4" align="center">$textcolor2">"._URL."n"
            
$cols 4
            if(
is_admin($admin)) { 
                
$cols 5
                echo 
"$bgcolor4" align="center">$textcolor2">"._FUNCTIONS."n"
            } 
            echo 
""
            
$a 0
            
$dcolor_A "$bgcolor2"
            
$dcolor_B "$bgcolor1"


            
$num_users sql_num_rows($result$dbi); //number of users per sorted and limit query 
            
if ( $num_rows_per_order 0  ) { 
                while(
$user sql_fetch_array($result$dbi)) { 
                    
$dcolor = ($a == $dcolor_A $dcolor_B); 
                    echo 
"$dcolor">modules.php?name=Your_Account&op=userinfo&username=$user[username]">$textcolor1">$user[username] n"
                    echo 
"$dcolor">$textcolor1">$user[name] n"
                    echo 
"$dcolor">$textcolor1">$user[femail] n"
                    if (
$user[user_website] == "") { 
            
$url2 " "
            } else { 
            
$urlno eregi_replace("http://","",$user[user_website]); 
            
$url2 "http://$urlno" target="new">"._HOMEPAGE.""; 
            

            echo 
"$dcolor" align="center">$url2n"
                    if(
is_admin($admin)) { 
                        echo 
"$dcolor align=center>content" color="$textcolor1">[ modules.php?name=Your_Account&file=admin&op=modifyUser&chng_uid=$user[user_id]">"._EDIT." | n"
                        echo 
"modules.php?name=Your_Account&file=admin&op=deleteUser&chng_uid=$user[user_id]">"._DELETE." ]n"
                    } 
                    echo 
""
                    
$a = ($dcolor == $dcolor_A 0); 
                } 
                
// start of next/prev/row links. 
                
echo "n$cols' align='right'>n"
        echo 
"

"

        
OpenTable(); 
                echo 
"t"

                if ( 
$num_rows_per_order $pagesize ) { 
                    
$total_pages ceil($num_rows_per_order $pagesize); // How many pages are we dealing with here ?? 
                    
$prev_page $page 1

                    if ( 
$prev_page ) { 
                        echo 
"$module_name&letter=$letter&sortby=$sortby&page=$prev_page'>"
                        echo 
"images/left.gif" border="0" alt=""._PREVIOUS." ($prev_page)" title=""._PREVIOUS." ($prev_page)">"
                    } else { 
                        echo 
" n"
                    } 

                    echo 
""
                    echo 
"$num_rows_per_order "._USERSFOUND.$letter (
$total_pages "._PAGES.", $num_users "._USERSSHOWN.")"
                    echo 
""

                    
$next_page $page   1
                    if ( 
$next_page <= $total_pages ) { 
                        echo 
"$module_name&letter=$letter&sortby=$sortby&page=$next_page'>"
                        echo 
"images/right.gif" border="0" alt="Next Page ($next_page)" title="Next Page ($next_page)">"
                    } else { 
                        echo 
" n"
                    } 
    
/* Added a numbered page list, only shows up to 50 pages. */ 

                        
echo "3" align="center">"
                        echo 
[ "

                        for(
$n=1$n $total_pages$n  ) { 


                            if (
$n == $page) { 
                echo 
"$n"

                            } else { 
                echo 
"$module_name&letter=$letter&sortby=$sortby&page=$n'>"
                echo 
"$n"
                } 
                            if(
$n >= 50) {  // if more than 50 pages are required, break it at 50. 
                                
$break true
                                break; 
                            } else {  
// guess not. 
                                
echo " | "
                            } 
                        } 

                        if(!isset(
$break)) { // are we sopposed to break ? 
                
if ($n == $page) { 
                            echo 
"$n"

                } else { 
                            echo 
"$module_name&letter=$letter&sortby=$sortby&page=$total_pages'>"
                            echo 
"$n"
                } 
                        } 
                        echo 
] "
                        echo 
""

    
/* This is where it ends */ 
                
}else{  // or we dont have any users.. 
                    
echo ""
                    echo 
"$num_rows_per_order "._USERSFOUND.$letter"
                    echo 
""

                 } 

                 echo 
"n"
         
CloseTable(); 
                echo 
"n"

                 
// end of next/prev/row links 

            
} else { // you have no members on this letter, hahaha 
                
echo "$dcolor_A" colspan="$cols" align="center">
n"

                echo 
"$textcolor1">"._NOMEMBERS.$lettern"
                echo 
"
n"

            } 

            echo 
"n
n"

        } 

    
CloseTable(); 
        include(
"footer.php"); 

?>

12
tzvook
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/3/19 22:53

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


Quote:

wtravel wrote:
tzvook,

It should be possible to get all first letters of data in a column from the query results, but that would still require the query to get all results.

What I would do is create an extra column with the first letter of the category or title or whatever column you would like to use to filter on alphabet. Update the column with the first letters of the already existing data, and adjust the insert and update queries to fill this column based on the data entry.

Then you can adjust the query to only select records that match the letter in the "alphabetical" parameter in your url. This will not only speed up queries, it will also save calculation time.

Martijn


Yep, will speed up for sure, but then you'll need to do it also when editing a record, when users asking to modify it ....

13
wtravel
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes

Yes, upon saving and updating the listing, the script should get the first letter from the posted title. In the update query also update the first letter field.

I will use this concept in the directory module I am developing.

Martijn

14
tzvook
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/3/20 7:41

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


Hello Martijn
I'm trying to find out how it can be used as a wide system module hack, and the "letter" function is quite easy to implement @ modules like "MyLinks , Xdirectory , Xphones (Xdir hack) and so on" so help is needed in that area (can you look @ the code I posted from phpNuke ?)

I'm aware of your new project and waiting for the first release
but I'm looking a wider solution - that could be impolemented if needed to a lot of modules - the Alphabet search menu is quite importand for sites with 1000 members and above - especialy for modules that deals with phonebooks or members homepages - to my opinion, users are the heart of every site/system and as such , user interface needs to be the first concern of the developer (which xoops, though is an amasing system, is not so good at ... so I try to improove user's ability fo find things without the need to go to XOOPS search all the time).

Quite funny that no module has this option working correctly, 5 address modules in the Repository, non with alphabetic order ..... I want to make a hackd Xdir for that, but the "letters()" code is not acurate and as seen @ the PHPnuke ... is just part of the full code.

15
wtravel
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes

Tzvook,

Can you check which queries the MySQL debug window comes up with and post it to me when you click on the 'b' letter (list)?

Martijn

16
tzvook
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/3/21 9:19

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


Quote:
wtravel wrote:
Can you check which queries the MySQL debug window comes up with and post it to me when you click on the 'b' letter (list)?


I'm uploading it to my localhost site, as I can't do it on a "Live" site....
Probably a bit later ...

17
tzvook
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/3/29 8:27

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


Quote:

wtravel wrote:
Tzvook,

Can you check which queries the MySQL debug window comes up with and post it to me when you click on the 'b' letter (list)?

Martijn



Hello Martijn
Sorry for the delay .... lots of holidays here ... too many
PHP/SMARTY/MYSQL debug gave me just a lot of theme problems along with Multimenue notices ....
I can see from the PHPnuke I posted above that the problem is that the "letters()" don't count the rows it gets from the database, the WFteam's "letters()" function seem to be based completely on that PHPnuke code... simply without doing it the right way ... a quick glance in the code shows it.
I'm not a coder (just a little playing around), so solving it is far from reach, though, I can see that the PHPnuke code is dealing with it ....
If you want to see the the Xdirectory (with the letters() but without the PHPnuke code ... here it is: http://www.meant4u.com/tmp/xdirectory.zip

The phpnuke code is above, hope it will make sense for you or any other coder here ... (it will serve the xdir + a few phonebooks + every module that it can be iplemented in ... a much needed addition for big sites that needs this sorting for getting to the data quicker...)

18
tripmon
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/3/29 8:46

  • tripmon

  • Module Developer

  • Posts: 462

  • Since: 2004/2/28


Hi
I'm currently working on providing another xdir version which employs this. I should have a beta out by next week sometime (maybe sooner). Just thought I would mention in case you're not in a huge rush.

Though I have yet to work on the alpha code, off of the top of my head I would use hard code the A|B|Cs as links to a new page (alphaCat.php -copy of viewcat.php) using alpha=A as a var. and then perform a SQL LIKE $alpha%. That way you don't need to change anything in the db, or the existing files (except inserting the hardcoded A|B snip).

More soon.

19
wtravel
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes

Tripmon,

What kind of new xdirextory are you making? Any new features that will be in efqDirectory as well?

Martijn

20
tzvook
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/3/29 8:56

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


Hello tripmon
Rush ... Desperation is the word ... site is on the air, phonebook has ~ 600 records which sort weirdly aufull, like I mentioned in the begining.
All are mad about me that I told them to fill the phonebook, and I couldn't find any solution

I think the letters() should work good ... just that the WFteam didn't took the whole code for it... ... were it counts the database rows.

It's working in some of the letters fine, but with others it don't ... if you try my Xdir version you'll see.
I would have pointed you to a live site, but you probably can't read Hebrew...

Did I mentioned how lost I am ? ? ?
I thought of using it for "Homepages" module too, but the Xdir problem is killing me.


wtravel
Can you look @ the code, tell me if it can be done ?

Login

Who's Online

324 user(s) are online (180 user(s) are browsing Support Forums)


Members: 0


Guests: 324


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits