<?
/******************************************************************************
 get_all_links_cat function
 by Ying Zhang (Dodo) http://pure-essence.net
 
 STICK THIS FUNCTION in my-hacks.php and then follow the instruction to use it.

 This function is an add-on to get_linksbyname template function. It will list 
all of your links under all categories. It also allows to add some html before 
the category is shown, after it's shown and after the entire list of links are 
shown for the category.

 For example this is how I want my links to look:
    <div class="sidebarWrapper">
    <div class="sidebar">

    <h4>MY CATEGORY NAME</h4>
    <ul>
    <li><a href="#">MY LINK 1</a></li>
    <li><a href="#">MY LINK 2</a></li>
    <li><a href="#">MY LINK 3</a></li>
    </ul>

    </div>
    </div>

Then call the function with following arguments
get_all_links_cat("<div class=\"sidebarWrapper\">\n<div 
class=\"sidebar\">\n<h4>", "</h4>\n<ul>", "</ul>\n</div>\n</div>", "<li>\n", 
"\n</li>", "\n</li>\n<li>\n", FALSE, "name",FALSE,FALSE,-1,TRUE);

Argument explanation:
1st - html before all
2nd - html after category name
3rd - html after all
the rest of the arguments follows strictly the 2nd to last arguments here
http://wiki.wordpress.org/get_linksbyname
******************************************************************************/

/* control your links further */
function get_all_links_cat($beforeall$aftercatname$afterall$beforeonelink
$afteronelink$betweentwolinks$show_images$order$show_description
$show_rating$limit$show_updated) {
    global 
$wpdb$tablelinks$tablelinkcategories;

    
$request "SELECT DISTINCT link_category FROM $tablelinks ORDER BY 
link_category"
;
    
$linkcats $wpdb->get_results($request);
    foreach(
$linkcats as $thislink) {
        
// get cat name
        
$request2 "SELECT cat_name FROM $tablelinkcategories WHERE 
cat_id='"
.$thislink->link_category."'";
        
$catname $wpdb->get_results($request2);
        
$thiscatname $catname[0]->cat_name;
        
        echo 
$beforeall.stripslashes($thiscatname).$aftercatname;
        
// uses wp build in template function
        
echo get_linksbyname($thiscatname$beforeonelink
$afteronelink$betweentwolinks$show_images$order
$show_description$show_rating$limit$show_updated);
        echo 
$afterall;
    }

}