how to get all the values ​​in a single variable of the query?

advertisements
  • I want to display all the values present in ftext field i want to display all values into single variable like $spd.

  • When i print this variable $spd it displays only one (ftext)value.but ftext
    contains multiple values.

  • so please help me how to display all values using $spd variable
    Thanks in advance...!

    $query = mysqli_query($link, "SELECT id, ftext from projectfield");
    while($row = mysqli_fetch_array($query))
    {
    $spd = $row['ftext'];
    }
    
    

Every time variable updates so it contains only last values. Below approaches resolve it:-

#Either print all values
$query = mysqli_query($link, "SELECT id, ftext from projectfield");
while($row = mysqli_fetch_array($query)){
  echo $spd = $row['ftext'];
}

or

# or hold ftext in array and then use this
$spd = array();
$query = mysqli_query($link, "SELECT id, ftext from projectfield");
while($row = mysqli_fetch_array($query)){
   $spd[] = $row['ftext'];
}
foreach($spd as $val){
  echo $val;
}