product table structure is given below
CREATE TABLE `products` (
`id` int(6) unsigned NOT NULL AUTO_INCREMENT,
`category_id` int(6) unsigned NOT NULL,
`name` varchar(30) NOT NULL,
`unit_id` int(6) unsigned NOT NULL,
`brand_id` int(6) unsigned NOT NULL,
`orignalCost` int(30) NOT NULL,
`saleprice` int(30) NOT NULL,
`deleted` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
KEY `fk-to-uom` (`unit_id`),
KEY `fk-to-brand` (`brand_id`),
KEY `category_id` (`category_id`),
CONSTRAINT `fk-to-brand` FOREIGN KEY (`brand_id`) REFERENCES `brands` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `products_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=230 DEFAULT CHARSET=utf8mb4
Can someone please tell me what mistake i'm making as var_dump() displays the NUll values......is there any mistake in mysqli_fetch_array? it is showing like that "array(1) { [0]=> NULL } "
$selected_items_values = $_POST['product_id'];
$prices = [];
foreach($selected_items_values as $prud)
{
if(isset($prud))
{
$priceSql = "SELECT saleprice from products where id = ' $prud ' ";
$price=mysqli_query($db,$priceSql);
$price = mysqli_fetch_array($price);
array_push($prices , $price);
var_dump($prices);
}
}
EDITED ANSWER
Here is sample table I've created. (I removed foreign keys)
Here is sample insert statements
Here is sample data I've entered.
Here is db connect get all data via PHP.
Here is the result of above. You can see I have 6 rows.
In order to loop through php object use foreach
Foreach result goes like
In order to get only
salepriceuse it like below.So this is how you can get. Rest of it up to you whatever you want to do with it.