-2
<?php
    include('includes/function.php');
    $stmt = $pdo->prepare('
SELECT * 
  FROM tender_form_data
     , tender_letter_com 
 WHERE tender_letter_com.comid = tender_form_data.comid 
   and tno="tt"
');
    $stmt->execute();
    $stampfile = $stmt->fetch(PDO::FETCH_ASSOC);
    $sfile=$stampfile['itemname'];
    $sfile=explode(" , ",$sfile);
    $n=count($sfile);
    for($i=0;$i<$n;$i++){
    echo $sfile[$i].'<br>';
    }
?>
i am using this html code for inserting array in database

Current Ouput:

item1
item2
item2
item1
item2

But i want only unique value like

item1
item2

Any suggestion will be helpful

  • It looks like you store multiple items in a single field of your database? This is a fundamental design mistake. Normalise your tables properly and then this problem will not arise - you would be able to filter for the values you want using a WHERE clause in the SQL – ADyson Feb 10 '21 at 22:55
  • If you don't understand @ADyson has said, you can use DISTINCT in your SQL statement as follows. – Curtis Lanz Feb 10 '21 at 22:57
  • actually i am taking value from in an array that's going like item1,item2, an so what else i can use? ADyson – Đęĕpák Ğųpţą Feb 11 '21 at 07:46

1 Answers1

0

There are 2 possibilities the first one is in PHP:

<?php
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
?>

The above example will output:

Array
(
    [a] => green
    [0] => red
    [1] => blue
)

Or you can use SELECT DISTINCT in your SQL query this way the query outputs only distinct(different) values.

Arne
  • 11
  • 1