Foros del Web » Programando para Internet » PHP »

[problema & Ayuda] Ordenamiento

Estas en el tema de [problema & Ayuda] Ordenamiento en el foro de PHP en Foros del Web. Hola! yo de nuevo, si :( Bueno, en esta oportunidad, queria consultar como puedo hacer para que al elegir desde un list/menu se me ordenen ...
  #1 (permalink)  
Antiguo 09/05/2008, 02:20
 
Fecha de Ingreso: marzo-2008
Mensajes: 171
Antigüedad: 16 años, 1 mes
Puntos: 0
[problema & Ayuda] Ordenamiento

Hola! yo de nuevo, si :(

Bueno, en esta oportunidad, queria consultar como puedo hacer para que al elegir desde un list/menu se me ordenen los valores recogidos desde mi base de datos.

Aqui: http://190.17.18.210/uf/content2.php esta el ejemplo de lo que quisiera hacer, en el list/menu de arriba, quiero q cuando elijo la opcion, me ordene las noticias de abajo por Autor / Fecha o Titulo.

Gracias y espero alguien me de una manito.

Besos! Agus.
  #2 (permalink)  
Antiguo 09/05/2008, 02:40
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Re: [problema & Ayuda] Ordenamiento

genial!!

es necesario en pensar como Javascript en este caso....

tendrias que crear, un objeto JSON con la informacion de los indices a ordenar (abreviados)
en el caso de autor y titulo, como string... y ya sabes, fecha... como INT ((como si lo obtuvieses con time() o mktime()) para ordenamiento numerico de fecha...

ahora, exportas todo a JSON... y necesitas implementar un sistema de ordenamiento en base a este objeto de Javascript

en realidad se me ocurrio solo este ejemplo:

{'notices':
[
{title:'No se', author:'yo', date:123},
{title:'SI se!', author:'no', date:456}
]
}

algo asi es la forma del JSON... investiga eso
pero mi idea es.. usar algun for para reordenar este objeto respectivamente.... uff

te recomiendo que vayas con los del foro de Javascript, suerte!
-----------------------------------------------------------------------------

Edito: o era desde PHP.... cuando presiones <Actualizar>

perdon... eso seria MySQL.. con la sentencia

ORDER BY campo [ASC/DESC]

[ASC/DESC] puedes ordenar como suena, normal.. o al reves
donde campo es titulo, autor, etc... de tus columnas en tu tabla

Ej:

SELECT * FROM notas ORDER BY fecha DESC

¿ordenaria de abajo hacia arriba??? alguien expliquenos!!!

Última edición por pateketrueke; 09/05/2008 a las 02:47 Razón: PHP.. foo
  #3 (permalink)  
Antiguo 09/05/2008, 02:58
 
Fecha de Ingreso: marzo-2008
Mensajes: 171
Antigüedad: 16 años, 1 mes
Puntos: 0
Re: [problema & Ayuda] Ordenamiento

Gracias por la respuesta! aunque sinceramente no te entendi :(

El codigo por si sirve es:

Código PHP:
<?php

require_once('Connections/uf.php');

mysql_select_db($database_uf$uf);
$query_mostrar_noticias "SELECT * FROM noticias ORDER BY fecha DESC";
$mostrar_noticias mysql_query($query_mostrar_noticias$uf) or die(mysql_error());
$row_mostrar_noticias mysql_fetch_assoc($mostrar_noticias);
$totalRows_mostrar_noticias mysql_num_rows($mostrar_noticias);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>

</head>

<body bgproperties="fixed">
<table width="490" cellspacing="0" cellpadding="0">
  <tr>
    <td align="right"><form id="form1" name="form1" method="post" action="">
      <label>
        <span class="Estilo8"><strong>Ordenar noticias por</strong>:</span>
        <select name="orden" id="orden">
          <option value="autor" selected="selected">Autor</option>
          <option value="fecha">Fecha</option>
          <option value="titulo">Titulo</option>
        </select>
        <input type="submit" name="Submit" value="Actualizar" />
        </label>
      </form></td>
  </tr>
</table>
<table width="490" height="145" align="left" cellpadding="0" cellspacing="0">
  <tr>
    <td width="664" height="143" valign="top"><?php do { ?>
      <?php if ($totalRows_mostrar_noticias 0) { // Show if recordset not empty ?>
          <table width="490" cellpadding="0" cellspacing="0">
          <tr>
            <td width="490"><span class="titulo1"><?php echo $row_mostrar_noticias['titulo']; ?></span>
                <table width="100%" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><img src="imagenes/blank.gif" width="1" height="1" /></td>
                  </tr>
                </table>
              <span class="etiquetas1">Autor:</span> <span class="contenidos"><?php echo $row_mostrar_noticias['autor']; ?></span> <span class="etiquetas1">Fecha de publicaci&oacute;n:</span> <span class="contenidos"><?php echo $row_mostrar_noticias['fecha']; ?></span><br />
              <table width="485" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><img src="imagenes/blank.gif" width="1" height="5" /></td>
                  </tr>
                  <tr>
                    <td><span class="resumen"><?php echo $row_mostrar_noticias['resumen']; ?></span></td>
                  </tr>
                  <tr>
                    <td align="right"><span class="Estilo6">Ver noticia completa <a href="/uf/pdf/noticia.php?id=<?php echo $row_mostrar_noticias['id']; ?>" target="_blank"><img src="imagenes/pdficon_small.gif" width="17" height="17" border="0" /></a></span></td>
                  </tr>
                  <tr>
                    <td height="8"><img src="file:///C|/SERVER/www/uf/imagenes/blank.gif" width="1" height="2" /></td>
                  </tr>
              </table></td>
          </tr>
        </table>
        <table width="150" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height="1" bgcolor="#FFFFFF"><img src="file:///C|/SERVER/www/uf/imagenes/blank.gif" width="1" height="1" /></td>
          </tr>
        </table>
        <table width="490" cellspacing="0" cellpadding="0">
          <tr>
            <td height="3"><img src="imagenes/blank.gif" width="1" height="1" /></td>
          </tr>
        </table>
        <?php // Show if recordset not empty ?>
      <?php } while ($row_mostrar_noticias mysql_fetch_assoc($mostrar_noticias)); ?></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result
($mostrar_noticias);
?>
Gracias de nuevo!

Besos, Agus!
  #4 (permalink)  
Antiguo 09/05/2008, 03:11
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Re: [problema & Ayuda] Ordenamiento

perdon... solo nota el

ORDER BY fecha DESC

el que usas....

si te das cuenta estas ya ordenandolo por fecha, descendientemente....
ahora, si lo cambias por...

ORDER BY autor ASC

se ordenara por autor, ascendentemente...


no se si me explique, pero con que modifiques tu consulta basta...

ORDER BY <?php print isset($_POST['orden'])? $_POST['orden']: 'fecha'.(isset($_POST['como'])? ' '.$_POST['como']: ' DESC'); ?>
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 18:31.