0

here's the code and i want to echo only 1 city from mysql database!

<?php


include('db.php');

    $queryss = mysqli_query($conn, 'SELECT * FROM areas');

    while ($rowx = mysqli_fetch_array($queryss)) {


        echo "{pro:'$rowx[1]',city:'$rowx[2]', dist:'$rowx[3]', town:'$rowx[4]', area:'$rowx[5]',subarea:'$rowx[6]',ucname:'$rowx[7]'},";

    }

    ?>

and i'm, getting this input here! 3 time karachi in my html, but i want only 1 of this city. SELECT DISTINCT is working in mysql but how can i use it in PHP?

enter image description here

David Duponchel
  • 3,813
  • 3
  • 27
  • 35

2 Answers2

1

Your query should be

SELECT * FROM areas GROUP BY id

I have tested it.

Rajesh
  • 15
  • 6
0

Use

SELECT DISTINCT column_name1,column_name2 FRAM areas

in your SQL where column_nameN stands for the columns you need for your output.

OR use something like this (untested):

$results = [];
while ($rowx = mysqli_fetch_array($queryss)) {
    $results[] = $rowx;
}
$results= array_unique($results);
foreach($results as $rowx) {
    echo "{pro:'$rowx[1]',city:'$rowx[2]', dist:'$rowx[3]', town:'$rowx[4]', area:'$rowx[5]',subarea:'$rowx[6]',ucname:'$rowx[7]'},";
}
Iarwa1n
  • 438
  • 2
  • 11