Read array from a field

Asked

Viewed 33 times

0

in an sql query, it returns me this value 10,30,40,50 of the fields" mark_ups_range"

How to read and quabrar in lines this values? exemology

10

30

40

50

$sql1 = "SELECT mark_ups_range FROM config_politicas WHERE id_transfer = '1' ";
$resultado1 = mysql_query($sql1) or die( mysql_error());
while ($linha = mysql_fetch_assoc($resultado1)) {

$id2=$linha['mark_ups_range'];// 10,30,40,50

}
$arr = explode(', ', $id2);
foreach ($arr as $v) {
echo '<br>';
echo $arr;
}
  • There’s an extra space in your explosion

  • Replace that $arr = explode(', ', $id2); therefore $arr = explode(',', $id2);.

  • returns me like this Array Array Array

1 answer

1


In his explode has an extra space. Another problem is that every repetition of foreach you are printing the value of $arr when you should actually print the value of $v. Do it this way:

$arr = explode(',', $id2);
foreach ($arr as $v) {
    echo '<br>';
    echo $v;
}

The as of foreach will cause each repeat to be picked up an item from the array and stored in the variable on the right, which in this case is $v.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.