Jump to content

Please help with query


lingo5
Go to solution Solved by Barand,

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
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);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.