Código
mis tablas son estas
function searchProduct($id,$main=false,$limit=false){ if($main !== false && $limit !== false){ $sql="SELECT * FROM product WHERE code like '%".$id."%' or product like '%".$id."%' ORDER BY idproduct ASC LIMIT $main,$limit"; }else{ $sql="SELECT * FROM product WHERE code like '%".$id."%' or product like '%".$id."%' ORDER BY idproduct"; } echo $sql; $this->conexion->conexion->set_charset('utf8'); $result=$this->conexion->conexion->query($sql); while($record = $result->fetch_array(MYSQL_NUM)){ $array[] = $record; } return $array; $this->conexion->cerrar(); }
Código
CREATE TABLE IF NOT EXISTS `product` ( `idproduct` INT(11) NOT NULL, `code` VARCHAR(15) NOT NULL, `product` VARCHAR(50) NOT NULL, `price` DECIMAL(9,2) NOT NULL, `stock` INT(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Volcado de datos para la tabla `product` -- INSERT INTO `product` (`idproduct`, `code`, `product`, `price`, `stock`) VALUES (1, 'MG01', 'IPHONE 4S', '5000.00', 6), (2, 'TCL01', 'IMAC', '5000.00', 6), (3, 'ILK059', 'SAMSUNG', '5000.00', 6), (4, '4520', 'HAWEI', '5000.00', 6), (5, 'A081', 'SNOWBOARD', '5000.00', 6), (6, 'MSD01', 'SKYBOARD', '5000.00', 6), (7, 'AUR01', 'SADDS', '5000.00', 6), (8, 'SA-205', 'CCD', '5000.00', 6), (9, 'KB-1830', 'USB', '5000.00', 6), (10, 'MGa01', 'MOVIES', '5000.00', 6), (11, 'PAS48', 'KNM', '5000.00', 6), (12, 'OE86Z', 'PJAGDS', '5000.00', 6), (13, 'HVMHFV', 'ASSAD', '5000.00', 6), (14, 'AFDD', 'CXVVXC', '5000.00', 6), (15, 'DASFSDFD', 'XCXCV', '5000.00', 6); -- -------------------------------------------------------- -- -- Estructura de tabla para la tabla `purchase` -- CREATE TABLE IF NOT EXISTS `purchase` ( `idpurchase` INT(11) NOT NULL, `user_iduser` INT(11) NOT NULL, `user_typeuser_idtypeuser` INT(11) NOT NULL, `product_idproduct` INT(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Volcado de datos para la tabla `purchase` -- INSERT INTO `purchase` (`idpurchase`, `user_iduser`, `user_typeuser_idtypeuser`, `product_idproduct`) VALUES (1, 1, 1, 10), (2, 2, 2, 10); ADD CONSTRAINT `fk_purchase_product1` FOREIGN KEY (`product_idproduct`) REFERENCES `product` (`idproduct`) ON DELETE NO ACTION ON UPDATE NO ACTION,