在循环中获取数组中的多个值

im having a problem in getting multiple values which i unload it from db and post to get all values by means of while loop but instead only the first value in array will display. here is my script:

submit.php

$res=mysql_query(select number from phonebook);
 while ($row = mysql_fetch_array($res))
 {
 $number = $row['number'];
}
<form method="post" action="send.php">
<input type="checkbox" name="number" value="<?php echo $number ?>">
<textarea name="message"></textarea>
<input type="submit" name="submit" value="submit">

send.php

$message = $_POST['message'];
$number = $_POST['number'];
exec('echo '.$message.' | mySmsGw --sendsms '.$number);

im trying to send message in multiple contact numbers and getting it with while loop but still only get the first value in number column.

thanks

If you want all numbers:

$number[] = $row['number'];

This is because of the following line inside the loop:

$number = $row['number'];

on each new iteration $number value is over written. So change it to:

$number[] = $row['number'];

So that it can hold multiple numbers.

$res = mysql_query("select number from phonebook");
$number = [];
while ($row = mysql_fetch_array($res)) {
  $number[] = $row['number'];
}

<form method="post" action="send.php">
<?php foreach ($number as $num) { ?>
<input type="checkbox" name="number[]" value="<?php echo $num; ?>">
<?php } ?>
<textarea name="message"></textarea>
<input type="submit" name="submit" value="submit">

POST:

$message = $_POST['message'];
$numbers = $_POST['number'];

foreach ($numbers as $number) {
 exec('echo '.$message.' | mySmsGw --sendsms '.$number);
}