<?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 );


    ?>

最佳答案

例如,您的阵列中有一些数据。您可以在字符串中使用implode数组,请参见下文

$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/

10-09 23:43
查看更多