Browse:
Injury Re
[Diagnostic diffic
Biological control
The purpose of the
In this interview,
Carcinoma in an il
Q:
JSTL: Setting
Familial acro-rena
There is always a
I have spent the lQ:
Cant get the data for this field
I was trying to get the value of 'product_name' by using this function
$products = [];
$query = "select id, product_name, prod_group from ebs_product_details where prod_group = ''";
$select_products = "select product_name, prod_group from ebs_product_details where prod_group = ''";
if ($result = mysqli_query($con,$query)) {
while($data = mysqli_fetch_assoc($result)){
if($data['product_name'] != ''){
$products[] = $data;
print_r($data);
var_dump($data['product_name']);
echo "
";
}
}
}
But I am not getting anything...
A:
You can use this sql:
$result = mysqli_query($con,"SELECT prod_group,product_name FROM ebs_product_details WHERE prod_group=''");
and if you need you can use this code too:
while($data = mysqli_fetch_assoc($result)){
if(empty($data['prod_group'])){
continue;
}
if($data['prod_group'] != ''){
$products[] = $data;
var_dump($data);
}
}
In if statement should check prod_group!=''
it will give you all name of the product without empty result
it will return empty result
i hope it helps :)
A:
The issue here is that you are only returning if the record is not empty, but the empty ones are not empty.
This could be done with a simple tweak to your query:
$products = [];
$query = "select id, product_name, prod_group from ebs_product_details where prod_group = ''";
$select_products = "select product_name, prod_group from ebs_product_details where prod_group = ''";
if ($result = mysqli_query($con,$query)) {
while($data = mysqli_fetch_assoc($result)){
if($data['product_name'] != ''){
$products[] = $data;
print_r($data);
var_dump($data['product_name']);
echo "
";
}
}
}
As you can see, instead of:
if($data['product_name'] != ''){
do
if($data['product_name'] != 'NULL'){
This will leave you with an array of all the results, or an empty array if there is no product_name in the product_details table
A:
Because you are performing SELECT * FROM EBS_PRODUCT_DETAILS where the value is NULL and because in mysql NULL != '', you cannot retrieve the field value.
SELECT product_name FROM EBS_PRODUCT_DETAILS where prod_group = '';
This way will show only records which have a field product_name, but the value will be NULL.
Edit: Since you mentioned that your prod_group column contains only 1 value, you need to use something like this, otherwise you will get an error:
SELECT `product_name`, `prod_group` from `ebs_product_details` where prod_group = '' LIMIT 1
Now, if you need the value:
if ($row = mysqli_fetch_assoc($result)) {
echo $row["product_name"];
}
Take a look at mysqli_fetch_assoc docs.