php - 将数据库中的值放入 '$string' 中

标签 php mysql

<?php


$dbHost = 'localhost'; // usually localhost
$dbUsername = 'root';
$dbPassword = '1234fedf';
$dbDatabase = 'smsmobile';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die ("Could not select database.");

$sql = "SELECT destinationaddress FROM reporting";
//print $sql;

$queryRes1 = mysql_query($sql);

while($rows=mysql_fetch_assoc($queryRes1))
{
$destinationaddress[] = $rows['destinationaddress']; 

}



$phones = $destinationaddress;


$sqlprefix = "SELECT country,prefix FROM countrycodes";
//print $sqlprefix;

$queryprefix = mysql_query($sqlprefix);

while($data=mysql_fetch_array($queryprefix))
{
$countryarray[] = $data['country']; 
$prefixarry[] = $data['prefix']; 
}
$countryname = implode(',',$countryarray); 
//print $countryname;
$prfixname = implode(',',$prefixarry);
//print $prfix;


$countrycode = $countryname;
$prfix = $prfixname;

foreach($countryname as $key => $value){
$result[] = 'country : '.$value.' prefix:'.$prfix[$key];
}

$allstring = implode(',',  $result);
print_r( $allstring );


    ?>

最佳答案

例如,您的数组有一些数据。您可以在字符串中内爆数组,请参见下文

$countryarray = array('Pakistan',  'India');
$prefixarry = array(971,  43);

$countrycode = $countryarray;
$prfix = $prefixarry;

foreach($countryarray as $key => $value){
$result[] = 'country : '.$value.' prefix:'.$prfix[$key];
}

$allstring = implode(',',  $result);
print_r( $allstring );

结果:

country : Pakistan prefix:971,country : India prefix:43

关于php - 将数据库中的值放入 '$string' 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23490129/

相关文章:

PHP、MySQL 和关联数组问题...?

python - MySQL 插入查询 - FLASK

c# - 使用日期函数进行 mysql 查询时遇到问题

PHP preg_split by new line with\R

php - 在 html 表中传递 $_POST ["variable"]

java - Android Java Http Post 到 PHP 服务器始终为 NULL?

mysql_secure_installation 问题 : access denied for user 'root' @'localhost'

php - 仅当输入文本不为空时才插入 mysql - Codeigniter

mysql - sql中的组合不重复

php - 在 Sugarcrm 中将联系人添加到目标列表时如何更新数据库