Ver Mensaje Individual
  #5 (permalink)  
Antiguo 19/09/2011, 13:20
Avatar de andresdzphp
andresdzphp
Colaborador
 
Fecha de Ingreso: julio-2011
Ubicación: $this->Colombia;
Mensajes: 2.749
Antigüedad: 12 años, 9 meses
Puntos: 793
Respuesta: Problema con consulta

A mi se me ocurre algo así, mira a ver si te sirve.

Código PHP:
Ver original
  1. <?php
  2. $c = mysql_connect('localhost', 'root', '12345');
  3. mysql_select_db('basededatos');
  4. $sql = 'select * from tabla';
  5. $res = mysql_query($sql) or die(mysql_error());
  6.  
  7. $id_inicio = 40;
  8. $tureg = '';
  9. $regs = array();
  10.  
  11. while ($reg = mysql_fetch_array($res)) {
  12.     if ($reg['id'] == $id_inicio) {
  13.         $tureg = $reg;
  14.     } else {
  15.         $regs[] = $reg;
  16.     }
  17. }
  18.  
  19. if (is_array($tureg)) {
  20.     echo $tureg['id'] . '<br />';
  21. }
  22.  
  23. foreach ($regs as $v) {
  24.     echo $v['id'] . '<br />';
  25. }

Edit: Igual no es el foro pero te dejo la forma con MySQL

Código SQL:
Ver original
  1. SELECT id, IF(id = 40, 1, 2) AS orden FROM tabla ORDER BY orden, id ASC
__________________
Si sabemos como leer e interpretar el manual será mucho más fácil aprender PHP. En lugar de confiar en ejemplos o copiar y pegar - PHP

Última edición por andresdzphp; 19/09/2011 a las 13:28