lingo5 Posted March 22, 2013 Share Posted March 22, 2013 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. Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted March 22, 2013 Solution Share Posted March 22, 2013 (edited) SELECT t_productos.*, marcas.marca_title_esp FROM t_productos INNER JOIN marcas USING (id_marca) WHERE id_subfamilia = %s AND producto_visible=1 Edited March 22, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
lingo5 Posted March 22, 2013 Author Share Posted March 22, 2013 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); Quote Link to comment Share on other sites More sharing options...
lingo5 Posted March 22, 2013 Author Share Posted March 22, 2013 Sorry Barand it wiorks....I had a typo. Many many many thanks for our help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.