Ver Mensaje Individual
  #7 (permalink)  
Antiguo 29/01/2016, 21:58
devil65
 
Fecha de Ingreso: marzo-2015
Mensajes: 184
Antigüedad: 9 años, 1 mes
Puntos: 3
Respuesta: extraer numeros pares de mi bd por id

el problema es que al hacer dos consultas se me duplican mis artículos queda por ejemplo
9--- 9 8-------8 77 66 55 44 33 22 11
par--par impar--impar......


Código PHP:
Ver original
  1. <?php
  2. require("banner/conexion.php");
  3. $query = "SELECT * FROM articulos order by id desc limit 6 ";
  4. $resultado =$conexion->query($query);
  5. while($row=$resultado->fetch_assoc()){
  6.     $ruta = "img/" . $row['imagen'];
  7.      
  8. $i = 0;
  9.      
  10.      while ($fila = $resultado->fetch_row()) {
  11.       if (($i++ % 2) == 1) {
  12.      
  13.      
  14. $class = 'imagen2'; /* esta es azul*/
  15. }
  16.  
  17. }
  18.  
  19.  
  20. ?>
  21.         <div class="imagen1">
  22.        
  23.         <img src="<?php echo $ruta; ?>" width="200" heigth="300">
  24.        
  25.        
  26.         <a href="http://localhost/WEB/confecoop/ubusina/public/articulos.php"></a>
  27.        
  28.         <h3><?php $cortar =($row['titulo']);
  29.         if ((strlen($cortar))) {
  30.             $cortar=substr($cortar, 0,35) ."..";}
  31.             echo $cortar;?></h3>
  32.  
  33.         <p><?php $cortar =($row['texto']);
  34.          $texto_size=140;
  35.          $cortar=substr($cortar, 0,$texto_size);
  36.          $index=strrpos($cortar, " ");
  37.          $cortar=substr($cortar, 0,$index); $cortar.="... Leer Mas";
  38.          echo $cortar;?></p>
  39.         <!--Aqui mostramos un string cortado-->
  40.  
  41.    </div>
  42.   </div>
  43.   </div>
  44.  
  45.  
  46. <!--aqui termina el articculo 1-->
  47. <!--- aqui empieza el articulo 2    amarillo-->
  48. <?php
  49. $query = "SELECT * FROM articulos order by id desc limit 6 ";
  50. $resultado =$conexion->query($query);
  51. while($row=$resultado->fetch_assoc()){
  52.     $ruta = "img/" . $row['imagen'];
  53.      
  54. $i = 0;
  55.      
  56.      while ($fila = $resultado->fetch_row()) {
  57.       if (($i++ % 2) == 1) {
  58.      
  59.      
  60. $class = 'imagen2'; /* esta es azul*/
  61. }
  62.  
  63. }
  64. ?>
  65. <div class="imagen2">
  66.        
  67.         <img src="<?php echo $ruta; ?>" width="200" heigth="300">
  68.        
  69.        
  70.         <a href="http://localhost/WEB/confecoop/ubusina/public/articulos.php"></a>
  71.        
  72.         <h3><?php $cortar =($row['titulo']);
  73.         if ((strlen($cortar))) {
  74.             $cortar=substr($cortar, 0,35) ."..";}
  75.             echo $cortar;?></h3>
  76.  
  77.         <p><?php $cortar =($row['texto']);
  78.          $texto_size=140;
  79.          $cortar=substr($cortar, 0,$texto_size);
  80.          $index=strrpos($cortar, " ");
  81.          $cortar=substr($cortar, 0,$index); $cortar.="... Leer Mas";
  82.          echo $cortar;?></p>
  83.         <!--Aqui mostramos un string cortado-->
  84.  
  85.    </div>
  86.   </div>
  87.   </div>
  88.  
  89. <?php } ?>
  90. <?php } ?>
  91.  
  92. </fieldset>
  93. </head>
  94. <body>
  95.  
  96. </body>
  97. </html>

Última edición por devil65; 29/01/2016 a las 22:03