Ver Mensaje Individual
  #7 (permalink)  
Antiguo 07/10/2010, 15:25
Avatar de galitcin
galitcin
 
Fecha de Ingreso: septiembre-2010
Ubicación: Barcelona
Mensajes: 30
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: Bucle "While" en consulta mysql

aqui va el codigo con el While

Código PHP:
Ver original
  1. <?php
  2.     $i = $j = 0;
  3.     $lastdate = "";
  4.     while($row=mysql_fetch_array($res))
  5.     {
  6.           /*Alternando color de la fila*/
  7.           if ($colorfila==0){
  8.               $color= "#FFFFFF";
  9.               $colorfila=1;
  10.         }else{
  11.               $color="#EBFAE2";
  12.               $colorfila=0;
  13.         }                    
  14.         /*cerrando el if de color fila*/
  15.    
  16.        
  17.     $date_formatted = date("Ymd", $row['timestamp']);
  18.         if($date_formatted != $lastdate)
  19.         {
  20.             if ($lastdate)
  21.             {
  22.                 //echo "<tr><td height=\"1\"></td></tr>";
  23.                 $j = 0;
  24.             }
  25.  
  26.             echo "<tr><td height=\"1\"></td></tr><tr><td class=\"datehead\" colspan=\"$colspan\">".QuickDate($row['timestamp'], FALSE, FALSE)."</td></tr><tr><td height=\"1\"></td></tr>";
  27.  
  28.             $lastdate = $date_formatted;
  29.         }
  30.  
  31.    
  32.         $css_class = "post" . (($j&#37;2)+1);
  33.    
  34.        
  35.         $i++; $j++;
  36.  
  37.        
  38.         $url = buildURL($target_view, array($xcityid, $row['catid'], $row['catname'],
  39.             $row['subcatid'], $row['subcatname'], $row['adid'], $row['adtitle']));
  40.      
  41.  
  42.      
  43.         $title_extra = "";
  44.        
  45.         if(!$xsubcatid)
  46.        
  47.         {
  48.            
  49.             $subcatlink = buildURL("ads", array($xcityid, $row['catid'], $row['catname'],
  50.                 $row['subcatid'], $row['subcatname']));
  51.                
  52.  
  53.             $title_extra = "&nbsp;- <a href=\"$subcatlink\" class=\"adcat\">$row[catname] $path_sep $row[subcatname]</a>";
  54.         }
  55.     ?>
  56.    
  57.     <tr style="background-color:<?php echo $color; ?>" onmouseover="this.style.background='#FEFED4';" onmouseout="this.style.background='<?php echo $color; ?>';" class="<?php echo $css_class; ?>">
  58.        
  59.              <td>
  60.                
  61.                 <a href="<?php echo $url; ?>" class="posttitle">
  62.  
  63.                 <?php
  64.                 if($row['picfile'] && $ad_thumbnails)
  65.                 {
  66.                     $imgsize = GetThumbnailSize("{$datadir[adpics]}/{$row[picfile]}", $tinythumb_max_width, $tinythumb_max_height);
  67.                 ?>
  68.                     <img src="<?php echo "$datadir[adpics]/$row[picfile]"; ?>" alt="Anuncios Gratis" border="0" width="80" height="60" align="left"  style="margin-right:5px;">
  69.                 <?php
  70.                 }
  71.                 else {
  72.                    
  73.                 echo '<img src="images/default.gif" alt="Anuncios Gratis" border="0" width="80" height="60" align="left"  
  74.                    style="margin-right:5px;">';
  75.                 }
  76.                 ?>
  77.                                    
  78.                 <?php echo $row['adtitle']; ?></a>
  79.                 <?php
  80.                 $loc = "";
  81.                 if($row['area']) $loc = $row['area'];
  82.                 if($xcityid <= 0) $loc .= ($loc ? ", " : "") . $row['cityname'];    // Version 5.0
  83.                 if($loc) echo "($loc)";
  84.                 ?>
  85.                 <?php
  86.                 if($ad_preview_chars)
  87.                 {
  88.                     echo "<span class='adpreview'>";
  89.                     $row['addesc'] = preg_replace("/\[\/?URL\]/", "", $row['addesc']);
  90.                     echo substr($row['addesc'],0,$ad_preview_chars);
  91.                     if (strlen($row['addesc'])>$ad_preview_chars) echo "...";
  92.                     echo "</span>";
  93.                 }
  94.                 ?>
  95.  
  96.  
  97.         </td>
  98.         </tr>
  99.  
  100.     <?php
  101.     }
  102. }
  103.  
  104. ?>