Foros del Web » Programando para Internet » PHP »

Comparador de Id - Comparando tres tablas..

Estas en el tema de Comparador de Id - Comparando tres tablas.. en el foro de PHP en Foros del Web. Saludos... tengo una duda y es q tngo una pagina de consumibles y articulos de computacion en donde contengo tres tablas en la base de ...
  #1 (permalink)  
Antiguo 21/02/2008, 09:36
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Exclamación Comparador de Id - Comparando tres tablas..

Saludos... tengo una duda y es q tngo una pagina de consumibles y articulos de computacion en donde contengo tres tablas en la base de datos q son

categoria
id, nombre

marca
id, Id_categoria, nombre, imagen

productos
id, Id_categoria, Id_marca, etc


ya llegue a la parte donde tengo q listar productos

por decirlo asi

Categorias

- Impresoras
- Consumibles
- Datacard

Doy click en impresoras y voy a las marcas q esta contiene

ahora es donde viene mi duda.. debo dar click en una marca y q esta me liste todas las impresoras contenidas en ella

o sea que deberia ser...

Id_categoria en la tabla productos = Id_categoria en la tabla marca = id en la tabla categoria...
mi pregunta es....
como seria la declaracion en este caso??? que debo hacer para que el mismo me extraiga solo las impresoras d esa marca????

Es urgente ... agradecido de quien pueda ayudarme!!!!
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #2 (permalink)  
Antiguo 21/02/2008, 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, 11 meses
Puntos: 2135
Re: Comparador de Id - Comparando tres tablas..

Pues si ya tienes en tu tabla productos el id_categoria y el id_marca solo seleccionas por decir los registros donde id_categoria sea igual a la categoría que estas listando y la id_marca sea igual a la marca que hiciste click.

Saludos.
  #3 (permalink)  
Antiguo 21/02/2008, 10:06
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: Comparador de Id - Comparando tres tablas..

Cita:
Iniciado por GatorV Ver Mensaje
Pues si ya tienes en tu tabla productos el id_categoria y el id_marca solo seleccionas por decir los registros donde id_categoria sea igual a la categoría que estas listando y la id_marca sea igual a la marca que hiciste click.

Saludos.
ok fijate.... ya saque conclusiones y bueno la idea es q compare el Id_marca de la tabla producto con la id de la tabla marca...
pues las marcas se repiten por categorias pero con id diferentes...

tons hago esto..

Código PHP:
<?php require_once('Connections/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_Recordset1 "-1";
if (isset(
$_GET['id'])) {
  
$colname_Recordset1 $_GET['id'];
}
mysql_select_db($database_connect$connect);
$query_Recordset1 sprintf("SELECT * FROM marca WHERE id = %s"GetSQLValueString($colname_Recordset1"int"));
$Recordset1 mysql_query($query_Recordset1$connect) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

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



?>
<table width="85" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="100"><a href="#" onclick="window.open('verimagen.php?pro_id=<?=$pro_id;?>;','verimagen', 'width=400,height=400'); return false;"><img src="images2/<?php echo $row_Recordset2['imagen']; ?>" width="100" height="100" border="0" class="bordeimg" /></a></td>
    <td width="75%">&nbsp;</td>
  </tr>
</table>
<?php
mysql_free_result
($Recordset1);

mysql_free_result($Recordset2);
?>
pero me sigue arrastrando el id incorrecto!!!!
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #4 (permalink)  
Antiguo 21/02/2008, 10:21
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: Comparador de Id - Comparando tres tablas..

listo Gator por tu ayuda :)

caso cerrado me di cuenta del error...
no era el id incorrecto era q el while estaba tomando el recordset q no era...

me quedo asi

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

$maxRows_Recordset1 10;
$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_connect$connect);
$query_Recordset1 sprintf("SELECT * FROM marca 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$connect) 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_connect$connect);
$query_Recordset2 "SELECT * FROM productos WHERE Id_marca =".$row_Recordset1['id'];
$Recordset2 mysql_query($query_Recordset2$connect) or die(mysql_error());
$row_Recordset2 mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 mysql_num_rows($Recordset2);



?>
<?php 
do { ?>
  <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td width="100"><a href="#" onclick="window.open('verimagen.php?pro_id=<?=$pro_id;?>;','verimagen', 'width=400,height=400'); return false;"><img src="images2/<?php echo $row_Recordset2['imagen']; ?>" width="100" height="100" border="0" class="bordeimg" /></a></td>
      <td width="400"><?php echo $row_Recordset2['nombre']; ?></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
      </table>
  <?php } while ($row_Recordset2 mysql_fetch_assoc($Recordset2)); ?>
  
  <?php
mysql_free_result
($Recordset1);

mysql_free_result($Recordset2);
?>
__________________
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 03:32.