目的是从 foreach 循环中获取每个值(电话号码)并使用它来查询 mysql 数据库,以便我也可以获得与该号码对应的名称
<?php
if (!empty($_POST)) {
$text = $_POST['message'];
$to = $_POST['recipients'];//this is an array
include('mysql_connect.php');//connect to my database
mysql_select_db("my_database");
$to = explode(", ",$to);
$to = implode(" ",$to);
if ($to != '' && $text != "") {
$phonenumbers = explode(';', $to);
if (!empty($phonenumbers)) {
foreach ($phonenumbers as $phonenumber) {;
$construct = "SELECT * FROM my_table WHERE mobile='$phonenumber'";//this is where my problem is, $phonenumber!!
$check = mysql_query($construct);
while($row = mysql_fetch_array($check)){
$name = $row[recipient_name];}//My aim is to use this name in the message body
$filename = "/send_message";//keep all messages in this file
$handle = fopen($filename .".LOCK", "x+");
if ($handle != false) {
fwrite($handle, "To: $phonenumber\n");
$text = "$name".$_POST['message'];//Every message should start with recipient name
fwrite($handle, $text);
fclose($handle);
}
}
}
}
}
?>