组消息从mysql获取关联数组

时间:2015-12-04 18:45:29

标签: php mysqli

我的群组邮件系统使用数组来控制数字和名称

$people = array(
    "+14031234567" => "Test Black Berry",
    "+14038999999" => "Test Android",
    "+14036519999" => "Test iPhone",
);

我试图使用php从mysql db获取此信息

<?php
include("config.php");
$connect = new mysqli("$dbhost","$dbuser","$dbpass","$dbname")
or die (mysqli_error());

$people=$connect->query("SELECT phone, name FROM contacts");
        while($row=$people->fetch_array(MYSQLI_ASSOC)){
        echo 
        $row ['phone']." => ".$row['name'].","; 
        }
?>

给我结果

   +14037777777 => Test Black Berry,
   +14038888888 => Test Android,
   +14039999999 => Test iPhone,

关闭但不完全一直。我错过了什么在此先感谢您的帮助

1 个答案:

答案 0 :(得分:0)

This the final code that works in my Message App 

<?php
include("../../lib/config.php");
$conn=mysqli_connect("$dbhost","$dbuser","$dbpass","$dbname")
or die (mysqli_error());
$query = "SELECT phone, name FROM grouplist";
$result = mysqli_query($conn, $query);
$people = array();
while ($row = mysqli_fetch_assoc($result)) {
    $people[$row['phone']] = $row['name'];
}   
?>