Jump to content

Please help with query


lingo5

Recommended Posts

hi,

I have a table for my products:

 

id_producto
id_familia
id_subfamilia
id_marca
producto_titulo_esp
producto_desc_esp
producto_precio
producto_precio_oferta
producto_novedad
producto_visible
producto_imagen_principal

and I have a table where I store product brands (marcas):

id_marca
marca_title_esp
marca_image

as you can see they both share the id_marca field.

 

I query the db to get products of a given sub_familia like so:

$colname_subcategorias_RS = "-1";
if (isset($_GET['id_subfamilia'])) {
  $colname_subcategorias_RS = $_GET['id_subfamilia'];
}
mysql_select_db($database_MySQLconnect, $MySQLconnect);
$query_subcategorias_RS = sprintf("SELECT * FROM t_productos WHERE id_subfamilia = %s AND producto_visible=1", GetSQLValueString($colname_subcategorias_RS, "int"));
$query_limit_subcategorias_RS = sprintf("%s LIMIT %d, %d", $query_subcategorias_RS, $startRow_subcategorias_RS, $maxRows_subcategorias_RS);
$subcategorias_RS = mysql_query($query_limit_subcategorias_RS, $MySQLconnect) or die(mysql_error());
$row_subcategorias_RS = mysql_fetch_assoc($subcategorias_RS);

this works fine, but what I need to do is to get the corresponding marca_title_esp from the table t_marcas ....how do I modify my query to do that???

 

Thanks a lot.

Link to comment
https://forums.phpfreaks.com/topic/276028-please-help-with-query/
Share on other sites

Thanks a lot Barand , but I am getting the same brand (marca) for all the records?

this is my query now

$colname_subcategorias_RS = "-1";
if (isset($_GET['id_subfamilia'])) {
  $colname_subcategorias_RS = $_GET['id_subfamilia'];
}
mysql_select_db($database_MySQLconnect, $MySQLconnect);
$query_subcategorias_RS = sprintf("SELECT t_productos.*, t_marcas.marca_title_esp FROM t_productos INNER JOIN t_marcas USING (id_marca) WHERE id_subfamilia = %s AND producto_visible=1", GetSQLValueString($colname_subcategorias_RS, "int"));
$query_limit_subcategorias_RS = sprintf("%s LIMIT %d, %d", $query_subcategorias_RS, $startRow_subcategorias_RS, $maxRows_subcategorias_RS);
$subcategorias_RS = mysql_query($query_limit_subcategorias_RS, $MySQLconnect) or die(mysql_error());
$row_subcategorias_RS = mysql_fetch_assoc($subcategorias_RS);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.