目的は、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);
}
}
}
}
}
?>