Foros del Web » Programando para Internet » PHP »

Condicionar listado de productos

Estas en el tema de Condicionar listado de productos en el foro de PHP en Foros del Web. Saludos, Hermanos tngo un listado de productos donde estos los divido por marcas pero quiero que si no tngo existencia d este productos en determinada ...
  #1 (permalink)  
Antiguo 07/01/2009, 14:46
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 7 meses
Puntos: 28
Condicionar listado de productos

Saludos,
Hermanos tngo un listado de productos donde estos los divido por marcas pero quiero que si no tngo existencia d este productos en determinada marca tampoco me muestre la marca ni el logo, pues el me muestra la marca seguida de los productos que en ella existen, pero si no hay productos en esa marca no quiero q se muestre, si no q salte a la marca siguiente

aqui tengo mi codigo...

Código PHP:
<?php require_once('Connections/cersol.php'); 
include(
'connect.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;
}
}

mysql_select_db($database_cersol$cersol);
$query_Recordset1 "SELECT * FROM marca_termicas";
$Recordset1 mysql_query($query_Recordset1$cersol) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

mysql_select_db($database_cersol$cersol);
$query_Recordset2 "SELECT * FROM imp_term";
$Recordset2 mysql_query($query_Recordset2$cersol) or die(mysql_error());
$row_Recordset2 mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 mysql_num_rows($Recordset2);
?>

 <table width="356" border="0" cellspacing="0" cellpadding="0">
  
  <tr>
    <td scope="col"><?php do { ?><?php if ($row_Recordset2['id_marca']!=0){ ?><table width="480" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="182" rowspan="2" align="left" valign="top"><table width="157" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><div align="left"><img src="logo/<?php echo $row_Recordset1['logo']; ?>" /></div></td>
            </tr>
        </table>
          </td>
        <td width="298" class="tituloMarca"><div align="left"><?php echo strtoupper($row_Recordset1['nombre']); ?></div></td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><?php 
        
// Variables de Configuraci&oacute;n -----------------------------------
// Define el numero de Filas
$n_filas=2;

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

$fotos = array();
        
$sql="SELECT * FROM imp_term WHERE id_marca=".$row_Recordset1['id']." and tipo = ".$type."";
mysql_select_db ('connect');
    
$sql_exec=mysql_query($sql);
    
    
/*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); ?> 
              <?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['nombre'];
                
                echo 
"<td width='180' height='15' border='0'><p align='left' class='marronlink'><a href='ficha_camioneta.php?id=".$row['id']."'>".$row['nombre']. "</a></p>";
            
                
$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>'
        
?> </td>
          </tr>
        </table>
          <br /></td>
      </tr>
      <tr>
        <td colspan="2" align="center" valign="top">&nbsp;</td>
        </tr>
      <tr>
        <td colspan="2" align="center" valign="top">&nbsp;</td>
      </tr>
    </table>
          <?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); ?><?php }?></td>
  </tr>
  <tr>
    <td scope="col"></td>
  </tr>
</table>
  

  <p class="tituloQUIENES">
    <?php
mysql_free_result
($Recordset1);
?>
URL de muestra
http://cersolve.com/prueba/print_ord.php?tipe=2

Gracias
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...

Última edición por T4ke0veR; 07/01/2009 a las 14:54
  #2 (permalink)  
Antiguo 07/01/2009, 14:54
 
Fecha de Ingreso: mayo-2006
Ubicación: Bogotá
Mensajes: 2.061
Antigüedad: 17 años, 11 meses
Puntos: 50
Respuesta: Condicionar listado de productos

Lo que se me ocurre es que primero haga una inner join entra las tablas marcas y preductos. dentro de ese hay si consulta los datos de cada una de las marcar que arrojo esa primera consulta y luego consulta los productos de la marca en la que este actualmente. Con eso solo le mostrara las marcas que tengan productos asociados.


Queda un poco largo pero eso le permitiria hacer esto.
  #3 (permalink)  
Antiguo 07/01/2009, 15:13
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: Condicionar listado de productos

aja aja... un inner join???? explicame por fa... soy un diseñador curioseando en php he aprendido mucho pero aun me faltan cosas
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #4 (permalink)  
Antiguo 07/01/2009, 15:28
 
Fecha de Ingreso: mayo-2006
Ubicación: Bogotá
Mensajes: 2.061
Antigüedad: 17 años, 11 meses
Puntos: 50
Respuesta: Condicionar listado de productos

con inner join consulta datos de dos tablas que tengan alguna relacion y solo trae los que esten en ambas tablas por eso no le traeria las marcas que no tienen productos


SELECT campos FROM marcas INNER JOIN producto ON marcas.codmarca = producto.idmarca;

aca hace el while para recorrer el resultdo de la consulta

Ahora lo que yo haria es otro inner join pero colocandole la condicion de que el id de la marca sea el actual.

SELECT camposdelproducto FROM marcas INNER JOIN producto ON marcas.codmarca = producto.idmarca and marcas.codmarca=MARCAACTUAL;

Ahora aca muestra la marca

Ahora con un while recorre los productos de la marca
  #5 (permalink)  
Antiguo 08/01/2009, 07:27
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: Condicionar listado de productos

y marca actual es = a???? el id q recojo desde el url????
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #6 (permalink)  
Antiguo 08/01/2009, 07:40
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: Condicionar listado de productos

ok fijate
Código PHP:
<?php require_once('Connections/cersol.php'); 
include(
'connect.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;
}
}

mysql_select_db($database_cersol$cersol);
$query_Recordset1 "SELECT * FROM marca_termicas INNER JOIN imp_term ON marca_termicas.id = imp_term.id_marca";
$Recordset1 mysql_query($query_Recordset1$cersol) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>

 <table width="356" border="0" cellspacing="0" cellpadding="0">
  
  <tr>
    <td scope="col"><?php do { ?><table width="480" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="182" rowspan="2" align="left" valign="top"><table width="157" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><div align="left"><img src="logo/<?php echo $row_Recordset1['logo']; ?>" /></div></td>
            </tr>
        </table>
          </td>
        <td width="298" class="tituloMarca"><div align="left"><?php echo strtoupper($row_Recordset1['nombre']); ?></div></td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><?php 
        
// Variables de Configuraci&oacute;n -----------------------------------
// Define el numero de Filas
$n_filas=2;

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

$fotos = array();
        
$sql="SELECT * FROM marca_termicas INNER JOIN imp_term ON marca_termicas.id = imp_term.id_marca and marca_termicas.id=".$type."";
mysql_select_db ('connect');
    
$sql_exec=mysql_query($sql);
    
    
/*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); ?> 
              <?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['nombre'];
                
                echo 
"<td width='180' height='15' border='0'><p align='left' class='marronlink'><a href='ficha_camioneta.php?id=".$row['id']."'>".$row['nombre']. "</a></p>";
            
                
$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>'
        
?> </td>
          </tr>
        </table>
          <br /></td>
      </tr>
      <tr>
        <td colspan="2" align="center" valign="top">&nbsp;</td>
        </tr>
      <tr>
        <td colspan="2" align="center" valign="top">&nbsp;</td>
      </tr>
    </table>
          <?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); ?></td>
  </tr>
  <tr>
    <td scope="col"></td>
  </tr>
</table>
  

  <p class="tituloQUIENES">
    <?php
mysql_free_result
($Recordset1);
?>
pero si van al URL http://cersolve.com/prueba/print_ord.php?tipe=2 aqui no deberia salir nada d nada .... y sale... me sigue listando las marcasd
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #7 (permalink)  
Antiguo 08/01/2009, 08:43
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: Condicionar listado de productos

ok lo resolvi pero cuando no consigue nada me lanza You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

asi lo hice y trato d condicionarlo para q no me salga el error pero sigue.. alguien me ayuda????

Código PHP:
<?php require_once('Connections/cersol.php'); 
include(
'connect.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;
}
}
$colname_Recordset2 "1";
if (isset(
$_GET['tipe'])) {
  
$colname_Recordset2 = (get_magic_quotes_gpc()) ? $_GET['tipe'] : addslashes($_GET['tipe']);
}
mysql_select_db($database_cersol$cersol);
$query_Recordset2 sprintf("SELECT * FROM imp_term WHERE tipo = %s"$colname_Recordset2);
$Recordset2 mysql_query($query_Recordset2$cersol) or die(mysql_error());
$row_Recordset2 mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 mysql_num_rows($Recordset2);

mysql_select_db($database_cersol$cersol);
$query_Recordset1 "SELECT * FROM marca_termicas WHERE id =".$row_Recordset2['id_marca'];
$Recordset1 mysql_query($query_Recordset1$cersol) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>

 <table width="356" border="0" cellspacing="0" cellpadding="0">
  
  <tr>
    <td scope="col"><?php if ($row_Recordset2['tipo']=="") { echo "No Existen registros";} else { do { ?><table width="480" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="182" rowspan="2" align="left" valign="top"><table width="157" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><div align="left"><img src="logo/<?php echo $row_Recordset1['logo']; ?>" /></div></td>
            </tr>
        </table>
          </td>
        <td width="298" class="tituloMarca"><div align="left"><?php echo strtoupper($row_Recordset1['nombre']); ?></div></td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><?php 
        
// Variables de Configuraci&oacute;n -----------------------------------
// Define el numero de Filas
$n_filas=2;

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

$fotos = array();
        
$sql="SELECT * FROM imp_term WHERE id_marca=".$row_Recordset1['id']." and tipo = ".$type."";
mysql_select_db ('connect');
    
$sql_exec=mysql_query($sql);
    
    
/*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); ?> 
              <?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['nombre'];
                
                echo 
"<td width='180' height='15' border='0'><p align='left' class='marronlink'><a href='ficha_camioneta.php?id=".$row['id']."'>".$row['nombre']. "</a></p>";
            
                
$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>'
        
?> </td>
          </tr>
        </table>
          <br /></td>
      </tr>
      <tr>
        <td colspan="2" align="center" valign="top">&nbsp;</td>
        </tr>
      <tr>
        <td colspan="2" align="center" valign="top">&nbsp;</td>
      </tr>
    </table>
          <?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); } ?></td>
  </tr>
  <tr>
    <td scope="col"></td>
  </tr>
</table>
  

  <p class="tituloQUIENES">
    <?php
mysql_free_result
($Recordset1);
?>
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #8 (permalink)  
Antiguo 08/01/2009, 09:47
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: Condicionar listado de productos

Pues con un simple if() ya tienes en $totalRows_Recordset2 la cantidad de valores, con un if() compruebas si hay resultados y en caso erroneo mandas el error.

Saludos
  #9 (permalink)  
Antiguo 08/01/2009, 09:53
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: Condicionar listado de productos

exacto gator y lo hice con un if en $totalRows_Recordset2 diciendole
Código PHP:
if ($totalRows_Recordset2==0) {echo "No existen registros":} else { 
pero simplemente sigue dando = ... el mismo problema!!!!!

miralo
Código PHP:
<?php require_once('Connections/cersol.php'); 
include(
'connect.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;
}
}
$colname_Recordset2 "1";
if (isset(
$_GET['tipe'])) {
  
$colname_Recordset2 = (get_magic_quotes_gpc()) ? $_GET['tipe'] : addslashes($_GET['tipe']);
}
mysql_select_db($database_cersol$cersol);
$query_Recordset2 sprintf("SELECT * FROM imp_term WHERE tipo = %s"$colname_Recordset2);
$Recordset2 mysql_query($query_Recordset2$cersol) or die(mysql_error());
$row_Recordset2 mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 mysql_num_rows($Recordset2);

mysql_select_db($database_cersol$cersol);
$query_Recordset1 "SELECT * FROM marca_termicas WHERE id =".$row_Recordset2['id_marca'];
$Recordset1 mysql_query($query_Recordset1$cersol) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>

 <table width="356" border="0" cellspacing="0" cellpadding="0">
  
  <tr>
    <td scope="col"><?php if ($totalRows_Recordset2==0) {echo "prueba";}  else { 
    
    do { 
?><table width="480" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="182" rowspan="2" align="left" valign="top"><table width="157" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><div align="left"><img src="logo/<?php echo $row_Recordset1['logo']; ?>" /></div></td>
            </tr>
        </table>
          </td>
        <td width="298" class="tituloMarca"><div align="left"><?php echo strtoupper($row_Recordset1['nombre']); ?></div></td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><?php 
        
// Variables de Configuraci&oacute;n -----------------------------------
// Define el numero de Filas
$n_filas=2;

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

$fotos = array();
        
$sql="SELECT * FROM imp_term WHERE id_marca=".$row_Recordset1['id']." and tipo = ".$type."";
mysql_select_db ('connect');
    
$sql_exec=mysql_query($sql);
    
    
/*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); ?> 
              <?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['nombre'];
                
                echo 
"<td width='180' height='15' border='0'><p align='left' class='marronlink'><a href='ficha_camioneta.php?id=".$row['id']."'>".$row['nombre']. "</a></p>";
            
                
$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>'
        
?> </td>
          </tr>
        </table>
          <br /></td>
      </tr>
      <tr>
        <td colspan="2" align="center" valign="top">&nbsp;</td>
        </tr>
      <tr>
        <td colspan="2" align="center" valign="top">&nbsp;</td>
      </tr>
    </table>
          <?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); } ?></td>
  </tr>
  <tr>
    <td scope="col"></td>
  </tr>
</table>
  

  <p class="tituloQUIENES">
    <?php
mysql_free_result
($Recordset1);
?>
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #10 (permalink)  
Antiguo 08/01/2009, 10:04
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: Condicionar listado de productos

Pues es obvio, el if lo haces después de hacer el query, el if para comparar tiene que ir antes del query, por eso te da error... Sabes de PHP?, recuerda que los programas se ejecutan de arriba a abajo y de izquierda a derecha, si tu pones una instrucción para condicionar algo después de lo que quieres condicionar no te sirve.

Saludos
  #11 (permalink)  
Antiguo 08/01/2009, 10:11
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: Condicionar listado de productos

pero es q fijate algo... si yo le digo q si el campo es diferente a cero me haga una nota el lo hace... el problema esta q cuando el campo no contiene valores no me cumple las condiciones establecidas....
de por si una vez lo habia hecho q si no me encontraba imagenes me dijera q no habian imagenes disponibles y justo esta despues de el query

Código PHP:
if ($row['img']=="" ){
       
       echo 
"No existen im&aacute;genes para este art&iacute;culo";
    
    }

    else{
        echo 
"<img src='galeria/".$row['img']."' width='57' height='50' border='0'  alt='Ampliar'/>";
    }
echo 
"</a>"
ese funcion a la perfeccion
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #12 (permalink)  
Antiguo 08/01/2009, 10:24
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: Condicionar listado de productos

Si pero es diferente, son dos condiciones diferentes, por ende lo que te digo, si lees mi mensaje y lo entiendes, puedes ver la causa de tu error.

En PHP y los lenguajes de programación en general, se ejecutan de arriba a abajo, y de izquierda a derecha, asi es como funciona, no puedes poner un if después y esperar que te condicione una parte que no esta dentro del bloque del if.

Para resolver tu problema tienes que condicionar tu query, si no por eso te lanza el error.

Saludos
  #13 (permalink)  
Antiguo 08/01/2009, 10:34
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: Condicionar listado de productos

asi??
Código PHP:
mysql_select_db($database_cersol$cersol);
$query_Recordset2 sprintf("SELECT * FROM imp_term WHERE tipo = %s"$colname_Recordset2);
$Recordset2 mysql_query($query_Recordset2$cersol) or die(mysql_error());
$row_Recordset2 mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 mysql_num_rows($Recordset2);
if (
$totalRows_Recordset2=="") {echo "No hay datos para mostrar";} 
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #14 (permalink)  
Antiguo 08/01/2009, 10:39
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: Condicionar listado de productos

fuuuuuunciono... gracias hermano!!!!
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #15 (permalink)  
Antiguo 08/01/2009, 11:11
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: Condicionar listado de productos

Compara con 0, no con un string vacio, la funcion mysql_num_rows te devuelve un numero, no te devuelve un string vacio.

Saludos
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:07.