Foros del Web » Programando para Internet » PHP »

Cambio de código

Estas en el tema de Cambio de código en el foro de PHP en Foros del Web. Saludos, tengo un sistema hecho en php donde se me listan productos segun la categoria y deseo cambiarlo.. pues lo desarrolle en DW los famosos ...
  #1 (permalink)  
Antiguo 04/06/2008, 08:56
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 7 meses
Puntos: 28
Cambio de código

Saludos,
tengo un sistema hecho en php donde se me listan productos segun la categoria y deseo cambiarlo.. pues lo desarrolle en DW los famosos recordsets.. bueno pero aqui me lista de manera vertical.. ahora quiero listar 3 productos por fila

aqui estan mis codigos
Actual en DW
Código PHP:
<?php require_once('Connections/multisillas.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$maxRows_Recordset1 30;
$pageNum_Recordset1 0;
if (isset(
$_GET['pageNum_Recordset1'])) {
  
$pageNum_Recordset1 $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 $pageNum_Recordset1 $maxRows_Recordset1;

$colname_Recordset1 "-1";
if (isset(
$_GET['id'])) {
  
$colname_Recordset1 $_GET['id'];
}
mysql_select_db($database_multisillas$multisillas);
$query_Recordset1 sprintf("SELECT * FROM categoria WHERE id = %s"GetSQLValueString($colname_Recordset1"int"));
$query_limit_Recordset1 sprintf("%s LIMIT %d, %d"$query_Recordset1$startRow_Recordset1$maxRows_Recordset1);
$Recordset1 mysql_query($query_limit_Recordset1$multisillas) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);

if (isset(
$_GET['totalRows_Recordset1'])) {
  
$totalRows_Recordset1 $_GET['totalRows_Recordset1'];
} else {
  
$all_Recordset1 mysql_query($query_Recordset1);
  
$totalRows_Recordset1 mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

mysql_select_db($database_multisillas$multisillas);
$query_Recordset2 "SELECT * FROM productos WHERE id_cat =".$row_Recordset1['id'];
$Recordset2 mysql_query($query_Recordset2$multisillas) or die(mysql_error());
$row_Recordset2 mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 mysql_num_rows($Recordset2);



?>
<link href="css/estilo.css" rel="stylesheet" type="text/css" />
<?php do { ?>
<table width="330" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" bgcolor="#CCCCCC"><table width="300" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="180" valign="top"><p><a href="esp_prod.php?id=<?php echo $row_Recordset2['id']; ?>"><span class="textoINDEX"><span class="textoMulti3"><br />
          <?php echo $row_Recordset2['nombre']; ?></span></span><br />
                  <br />
          </a><span class="textoINDEX"><span class="textotitResNot">C&oacute;digo:</span> <span class="textoMulti1"><?php echo $row_Recordset2['codigo']; ?></span></span></p>
            <p align="left"><span class="textoINDEX"><a href="ficha_prod.php?id=<?php echo $row_Recordset2['id']; ?>"><br />
                    <img src="imgs/boton_pro.jpg" width="112" height="22" border="0" /></a></span></p></td>
        <td width="19">&nbsp;</td>
        <td width="100" valign="middle"><p align="justify" class="textoINDEX"><a href="esp_prod.php?id=<?php echo $row_Recordset2['id']; ?>"><img src="imgprod/<?php echo $row_Recordset2['imagen']; ?>" width="100" height="100" border="0" class="bordeimg" /></a></p></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td align="center">&nbsp;</td>
  </tr>
</table>
<?php } while ($row_Recordset2 mysql_fetch_assoc($Recordset2)); ?>
  
  <?php
mysql_free_result
($Recordset1);

mysql_free_result($Recordset2);
?>
y tngo este q no se como adaptarlo al anterior q me hace lo q deseo
Código PHP:
<?php include('Connections/incomed.php');

// Variables de Configuración -----------------------------------
// Define el numero de Filas
$n_filas=3;

//***************************************************************
@$cat=$_REQUEST['id'];
//$cat=6;

$fotos = array();
        
$sql="SELECT * FROM imagenes where id_pro=".$producto_id."  ORDER BY id ASC";
mysql_select_db ('incomed');
    
$sql_exec=mysql_query($sql);
    function 
imagengrande() 

window.open("verimagen.php?imagen=/iamges2/<?=$imagen;?>""""width=450,height=300"); 
}
    
/*while($row=mysql_fetch_assoc($sql_exec)){
            $tottal=mysql_affected_rows(); // Calculo el numero total de itms a listar
            }*/
$tottal=113;
// ------------------------------------------------------------------------------------------------------------------
$vert=$tottal/$n_filas;
$vert=round($vert);

?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="100%" height="80"><table width="100%" height="80" border="0" align="center" cellpadding="0" cellspacing="0">
        
        <?php
        $a
=0;// Colocando el contador horizontal en 0
        
$i=1;// Colocando el contador vertical en 0
        
$w=0;//Colocando un contador para el mensaje de "No hay articulos en esta acategoria"
        
            
while($row=mysql_fetch_assoc($sql_exec)){
            
$w=w+1;
                if (
$a==0){
                echo 
'<tr>';
                }
                
$a=$a+1;
                
$fotos[$i.'-'.$a] = $row['img'];
                
                echo 
"<td height='80' width='53' border='0' ><a href=# onClick=\"window.open('verimagen.php?id=".$row['id']."; ','verimagen', 'width=530,height=470'); return false;\"><img src='images2/".$row['img']."' width='80' height='53' border='0'/></a>";
            
                
$r=$a;// contador remanente para listar imagenes sin exceso
                
                    
if ($a >= $n_filas) {
                    
$a=0;// reiniciando el contador horizontal
                    
$i=$i+1;// aumentando el contador vertical
                    
echo '</tr>';
                    } 
            if (empty(
$row)) {
        echo
"<table width='0' border='0' align='center' cellpadding='0' cellspacing='0'>
          <tr>
            <td width='257'><div align='center'>No hay articulos en esta categoria </div></td>
          </tr>
        </table>
        "
;
        break 
1;}
            
            }
            
         echo 
'</td>';
        
?>
        <?php /*if (empty($w)) {
        echo"<table width='0' border='0' align='center' cellpadding='0' cellspacing='0'>
          <tr>
            <td width='492'><div align='center'>No hay articulos en esta categoria </div></td>
          </tr>
        </table>
        ";
        exit;}
        */
?>
    </table></td>
  </tr>
</table>
alguien me hecha una manito??? gracias :)
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #2 (permalink)  
Antiguo 04/06/2008, 09:56
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 7 meses
Puntos: 28
Respuesta: Cambio de código

al menos leanlo jejeje.. ayuda plz... al menos orientacion en mas o menos q pasos debo seguir
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #3 (permalink)  
Antiguo 04/06/2008, 11:39
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Cambio de código

Solo es cuestión de que manejes correctamente tu loop do/while, prueba esto:
Código PHP:
<?php
$counter 
1;
$columns 3;
?>
<?php 
do { ?>
<table width="330" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" bgcolor="#CCCCCC">
    <!-- ITEM -->
<table width="300" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="180" valign="top"><p><a href="esp_prod.php?id=<?php echo $row_Recordset2['id']; ?>"><span class="textoINDEX"><span class="textoMulti3"><br />
          <?php echo $row_Recordset2['nombre']; ?></span></span><br />
                  <br />
          </a><span class="textoINDEX"><span class="textotitResNot">C&oacute;digo:</span> <span class="textoMulti1"><?php echo $row_Recordset2['codigo']; ?></span></span></p>
            <p align="left"><span class="textoINDEX"><a href="ficha_prod.php?id=<?php echo $row_Recordset2['id']; ?>"><br />
                    <img src="imgs/boton_pro.jpg" width="112" height="22" border="0" /></a></span></p></td>
        <td width="19">&nbsp;</td>
        <td width="100" valign="middle"><p align="justify" class="textoINDEX"><a href="esp_prod.php?id=<?php echo $row_Recordset2['id']; ?>"><img src="imgprod/<?php echo $row_Recordset2['imagen']; ?>" width="100" height="100" border="0" class="bordeimg" /></a></p></td>
      </tr>
    </table>
<!-- / ITEM -->
    </td>
    <?php if( ( $counter $columns ) == ) { ?></tr><tr><?php ?>
  </tr>
</table>
<?php $counter++; ?>
<?php 
} while ($row_Recordset2 mysql_fetch_assoc($Recordset2)); ?>
  #4 (permalink)  
Antiguo 04/06/2008, 12:33
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 7 meses
Puntos: 28
Respuesta: Cambio de código

perfecto.... ese archivo es un include... fijate lo q hice... en la pagina donde esta el include hice lo siguiente
Código PHP:
                          <?php         $categoria_id=$row_Recordset1['id']; 
                                include(
'prod_inc.php');
 
?>
y en el include

Código PHP:
<?php include('connect.php');

// Variables de Configuración -----------------------------------
// Define el numero de Filas
$n_filas=3;

//***************************************************************
@$cat=$_REQUEST['id'];
//$cat=8;

$fotos = array();
        
$sql="SELECT * FROM productos WHERE id_cat=".$cat."";
mysql_select_db ('connect');
    
$sql_exec=mysql_query($sql);
    function 
imagengrande() 

window.open("verimagen.php?imagen=/iamges2/<?=$imagen;?>""""width=450,height=300"); 
}
    
/*while($row=mysql_fetch_assoc($sql_exec)){
            $tottal=mysql_affected_rows(); // Calculo el numero total de itms a listar
            }*/
$tottal=113;
// ------------------------------------------------------------------------------------------------------------------
$vert=$tottal/$n_filas;
$vert=round($vert);

?>
<link href="css/estilo.css" rel="stylesheet" type="text/css" />

<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="100%" height="110" align="center"><table width="100%" height="110" border="0" align="center" cellpadding="0" cellspacing="0">
        
        <?php
        $a
=0;// Colocando el contador horizontal en 0
        
$i=1;// Colocando el contador vertical en 0
        
$w=0;//Colocando un contador para el mensaje de "No hay articulos en esta acategoria"
        
            
while($row=mysql_fetch_assoc($sql_exec)){
            
$w=w+1;
                if (
$a==0){
                echo 
'<tr>';
                }
                
$a=$a+1;
                
$fotos[$i.'-'.$a] = $row['imagen'];
                
                echo 
"<td height='80' width='80' border='0' class='textoMulti2' ><a href='ficha_prod.php?id=".$row['id']."'><img src='imgprod/".$row['imagen']."' width='90 height='90' border='0'/></a><br>";echo $row['nombre'];
            
                
$r=$a;// contador remanente para listar imagenes sin exceso
                
                    
if ($a >= $n_filas) {
                    
$a=0;// reiniciando el contador horizontal
                    
$i=$i+1;// aumentando el contador vertical
                    
echo '</tr>';
                    } 
            if (empty(
$row)) {
        echo
"<table width='0' border='0' align='center' cellpadding='0' cellspacing='0'>
          <tr>
            <td width='257'><div align='center'>No hay articulos en esta categoria </div></td>
          </tr>
        </table>
        "
;
        break 
1;}
            
            }
            
         echo 
'</td>';
        
?>
        <?php /*if (empty($w)) {
        echo"<table width='0' border='0' align='center' cellpadding='0' cellspacing='0'>
          <tr>
            <td width='492'><div align='center'>No hay articulos en esta categoria </div></td>
          </tr>
        </table>
        ";
        exit;}
        */
?>
    </table></td>
  </tr>
</table>
culminado...
Gracias!!!
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
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 17:53.