Priyanka Priyanka - 7 months ago 18
SQL Question

fetch SQLdata without column name in php

please tell me how to fetch data from MySql database in below format.

Now, i am getting data in below format

$sql="SELECT c.ad_id FROM `category_rel` c INNER JOIN tbl_category_master d ON c.category_id= d.fld_category_id WHERE d.fld_category_name IN ($category)";
$result1=$con->query($sql);
while ($row = mysqli_fetch_assoc($result1)) {
$output[] = $row;
}
$ids=json_encode(array($output));


Result:

[[{"ad_id":"2"},{"ad_id":"11"},{"ad_id":"28"},{"ad_id":"62"},{"ad_id":"64"}]]


But, I want in the below format:

["2","11","28","62"]


it should not come with the column name.

Answer

Try $output[] = $row['ad_id']; instead of $output[] = $row;

[Edit] Also remove array() function :

$sql="SELECT c.ad_id FROM `category_rel` c INNER JOIN tbl_category_master d ON c.category_id= d.fld_category_id WHERE d.fld_category_name IN ($category)";
$result1=$con->query($sql);
while ($row = mysqli_fetch_assoc($result1)) {
    $output[] = $row['ad_id'];
       }
$ids=json_encode($output);

Regards.