Foros del Web » Programando para Internet » PHP »

Ordenar alfabéticamente las categorías en un directorio

Estas en el tema de Ordenar alfabéticamente las categorías en un directorio en el foro de PHP en Foros del Web. Hola! Pueden ver mi directorio haciendo clic acá , como verán las categorías están desorganizadas (se organizan segun las añado, la última que añado queda ...
  #1 (permalink)  
Antiguo 01/10/2003, 09:22
Avatar de philipppe  
Fecha de Ingreso: marzo-2002
Ubicación: Uruguay
Mensajes: 706
Antigüedad: 22 años, 1 mes
Puntos: 0
Busqueda Ordenar alfabéticamente las categorías en un directorio

Hola! Pueden ver mi directorio haciendo clic acá, como verán las categorías están desorganizadas (se organizan segun las añado, la última que añado queda última), lo que yo quiero es que se organizen alfabéticamente, quizás me puedan ayudar, acá les paso el código de index.php:

Código PHP:
<?
include ("config.php");
include (
"include.php");
include (
"lang.php");
session_start();
if (
$c == 0) {    $c 1;    };
$sql mysql_query("SELECT name, title, description, pages, ref FROM {$prefix}categories WHERE id = $c");
$current_category mysql_fetch_array($sqlMYSQL_ASSOC);
if ((
$c 1) & !$current_category["name"]){
    
header("Location: {$dir}index.php");
};
if (!
$current_category["name"]) { $current_category["name"] = "Directory Search"; };
if (!
$current_category["title"]) { $current_category["title"] = $current_category["name"]; };
if (!
$current_category["description"]) { $current_category["description"] = $current_category["name"]." ".$current_category["title"]; };
$last_category false;
$ref $c;
while(!
$last_category){
    
$n_parent_categories += 1;
    
$sql mysql_query("SELECT id, name, ref FROM {$prefix}categories WHERE id = $ref");
    
$parent_categories[$n_parent_categories-1] = mysql_fetch_array($sqlMYSQL_ASSOC);
    if (
$parent_categories[$n_parent_categories-1]["ref"] == 0){
        
$last_category true;
    }else{
        
$ref $parent_categories[$n_parent_categories-1]["ref"];
    };
};
$sql mysql_query("SELECT {$prefix}categories.id, {$prefix}categories.name, COUNT({$prefix}pages.id) AS pages FROM {$prefix}categories LEFT JOIN {$prefix}pages ON {$prefix}pages.category = {$prefix}categories.id  WHERE ref = $c GROUP BY {$prefix}categories.id");
$n_subcategories mysql_num_rows($sql);
for (
$x 0$x $n_subcategories$x++){
    
$subcategories[$x] = mysql_fetch_array($sqlMYSQL_ASSOC);
};
if (
$current_category["pages"] == "y"){
    if (
$s == 0) { $s 1; };
    
$n 10;
    
$sql mysql_query("SELECT COUNT(*) AS total_pages FROM {$prefix}pages WHERE category = $c AND accepted = 'y'");
    
$total_pages mysql_result($sql,0,"total_pages");
    if (
$total_pages 0){
        
$sql mysql_query("SELECT id, url, title, description FROM {$prefix}pages WHERE category = $c AND accepted = 'y' ORDER BY id LIMIT ".($s-1).",$n");
        
$n_pages mysql_num_rows($sql);
        for (
$x 0$x $n_pages$x++){
            
$pages[$x] = mysql_fetch_array($sqlMYSQL_ASSOC);
        };
    };
};
$e min($s $n 1$s $n_pages 1);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE><? echo $current_category["name"]; if ($current_category["title"] != $current_category["name"]){ echo " - ".$current_category["title"]; };?></TITLE>
<META NAME="description" CONTENT="<? echo $current_category["description"]?>">
<META NAME="keywords" CONTENT="<? echo $current_category["name"]." ".$current_category["description"]?>">
<SCRIPT TYPE="text/javascript" SRC="style.js"></SCRIPT>
</HEAD>
<BODY>
<?
include ("starting_html.php");
?>
<DIV CLASS="main">
<DIV CLASS="logo"><A HREF="<? echo $dir?>index.php"></A></DIV>
<DIV CLASS="heading">
<H1><? echo $current_category["name"]?></H1>
<?
if ($c != 1){
    echo 
'<DIV CLASS="heading_path">'."\r\n";
    for (
$x $n_parent_categories-1$x >= 1$x--){
        if (
$x != $n_parent_categories-1) { echo " > "; };
        if (
$parent_categories[$x]["id"] == 1){
            echo 
'<A HREF="'.$dir.'index.php">'.$parent_categories[$x]["name"].'</A>';
        }else{
            echo 
'<A HREF="'.$dir.'index.php?c='.$parent_categories[$x]["id"].'">'.$parent_categories[$x]["name"].'</A>';
        };
    };
    echo 
' > '.$current_category["name"];
    echo 
"</DIV>\r\n";
};
?>
</DIV>
<?
if ($n_subcategories 0){
    echo 
'<DIV CLASS="categories">'."\r\n";
    echo 
'<DIV CLASS="categories_text">'.$t01.' "'.$current_category["name"].'":</DIV>'."\r\n";
    
$t ceil($n_subcategories/2);
    echo 
'<DIV CLASS="categories_blocks">'."\r\n";
    echo 
'<DIV CLASS="categories_blocks_left">'."\r\n";
    for (
$x 0$x $t$x++){
        echo 
'<DIV CLASS="categories_category"><DIV CLASS="categories_category_title">» <A HREF="'.$dir.'index.php?c='.$subcategories[$x]["id"].'">'.$subcategories[$x]["name"].'</A> </DIV>('.$subcategories[$x]["pages"].')</DIV>'."\r\n";
    };
    echo 
"</DIV>\r\n";
    echo 
'<DIV CLASS="categories_blocks_right">'."\r\n";
    if (
$n_subcategories 1){
        for (
$x $t$x $n_subcategories$x++){
            echo 
'<DIV CLASS="categories_category"><DIV CLASS="categories_category_title">» <A HREF="'.$dir.'index.php?c='.$subcategories[$x]["id"].'">'.$subcategories[$x]["name"].'</A> </DIV>('.$subcategories[$x]["pages"].')</DIV>'."\r\n";
        };
    }else{
        echo 
" \r\n";
    };
    echo 
"</DIV>\r\n";
    echo 
"</DIV>\r\n";
    echo 
"</DIV>\r\n";
};
?>
<DIV CLASS="search">
<FORM METHOD="get" ACTION="search.php">
<DIV CLASS="search_controls">
<INPUT TYPE="text" NAME="q" MAXLENGTH=100 CLASS="search_controls_text">
<INPUT TYPE="submit" VALUE="<? echo $t02?>" CLASS="search_controls_button">
</DIV>
<?
if ($current_category["pages"] == "y" || $_SESSION['admin']){
    echo 
'<DIV CLASS="search_add">'."\r\n";
    if(
$current_category["pages"] == "y"){
        echo 
'<A HREF="'.$dir.'add_url.php?c='.$c.'">'.$t03.'</A>'."\r\n";
    };
    if(
$_SESSION['admin']){
        echo 
'<A HREF="'.$dir.'admin_edit.php?c='.$c.'">'.$t04.'</A>'."\r\n";
    };
    echo 
"</DIV>\r\n";
};
?>
</FORM>
</DIV>
<?
if ($current_category["pages"] == "y"){
    if (
$n_pages 0){
        echo 
'<DIV CLASS="pages">'."\r\n";
        echo 
'<DIV CLASS="pages_results">'.$t05a.' '.$s.' - '.$e.' '.$t05b.' '.$total_pages.' '.$t05c.' "'.$current_category["name"].'":</DIV>'."\r\n";
        for (
$x 0$x $n_pages$x++){
            echo 
'<DIV CLASS="pages_page">'."\r\n";
            echo 
'<DIV CLASS="pages_page_title"><A HREF="'.$pages[$x]["url"].'">'.$pages[$x]["title"].'</A></DIV>'."\r\n";
            echo 
'<DIV CLASS="pages_page_description">'.$pages[$x]["description"].'</DIV>'."\r\n";
            echo 
'<DIV CLASS="pages_page_url">'.$pages[$x]["url"].'</DIV>'."\r\n";
            echo 
"</DIV>\r\n";
        };
        echo 
"</DIV>\r\n";
    }else{
        echo 
'<DIV CLASS="pages">'."\r\n";
        echo 
'<DIV CLASS="pages_results">'.$t06.' "'.$current_category["name"].'"</DIV>'."\r\n";
        echo 
"</DIV>\r\n";
    };
    if (
$s != || $e != $total_pages){
        function 
query($s){
            global 
$c;
            if (
$c != 1) { $query "?c=$c"; };
            if ((
$c != 1) & $s != 1){
                
$query .= "&s=$s";
            }elseif (
$s != 1){
                
$query "?s=$s";
            };
            return 
$query;
        };
        echo 
'<DIV CLASS="options">'."\r\n";
        if (
$s != 1){
            
$previous $s $n;
            echo 
'<A HREF="'.$dir.'index.php'.query($previous).'">'.$t07.'</A>'."\r\n";
        };
        for (
$x 1$x <= ceil($total_pages/$n); $x++){
            
$current = ($x-1) * $n 1;
            if (
$current == $s){
                echo 
$x."\r\n";
            }else{
                echo 
'<A HREF="'.$dir.'index.php'.query($current).'">'.$x.'</A>'."\r\n";
            };
        };
        if (
$e $s -$total_pages){
            
$next $s $n;
            echo 
'<A HREF="'.$dir.'index.php'.query($next).'">'.$t08.'</A>'."\r\n";
        };
        echo 
"</DIV>\r\n";
    };
};
include (
"links.php");
?>
</DIV>
<?
include ("ending_html.php");
?>
</BODY>
</HTML>
Si quieren más info del script o desean descargarlo: http://www.directory-search.org/directory_script.php

Desde ya, muchas gracias y espero que me puedan ayudar
__________________
Plugin de AdSense para Wordpress: http://adsensei.org
  #2 (permalink)  
Antiguo 03/10/2003, 11:58
Avatar de nuevo  
Fecha de Ingreso: mayo-2003
Ubicación: Spain
Mensajes: 2.009
Antigüedad: 20 años, 11 meses
Puntos: 2
para ordenar los resultados mostrados de cualquier consulta SQL

Código PHP:

mysql_query
("SELECT * FROM tu_tabla ORDER BY nombre_del_campo DESC"
DESC: descendente
ASC: ascendente
__________________
3w.valenciadjs.com
3w.laislatv.com
  #3 (permalink)  
Antiguo 03/10/2003, 15:55
Avatar de philipppe  
Fecha de Ingreso: marzo-2002
Ubicación: Uruguay
Mensajes: 706
Antigüedad: 22 años, 1 mes
Puntos: 0
Perdón, es que soy novato, donde tengo que cambiar eso? Gracias
__________________
Plugin de AdSense para Wordpress: http://adsensei.org
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:58.