Editing answer, as I got your idea wrong.
All you have to do is:
while ($myrow = mysqli_fetch_array($result)){
//.= means that it will connect all values, not override them
$id .= $myrow['id'];
// echo $id : 1234
}
THen echo $id
from anywhere.