gpt4 book ai didi

php - 列出数组 php 中的数字

转载 作者:行者123 更新时间:2023-11-29 19:08:09 24 4
gpt4 key购买 nike

对于我的工作,我必须使用 API 发送多条短信,并且我想将数字从 mysql 放入数组中,如下所示:

(这些数字在我的数据库中)

我想要这样的:

   $list_num = array(
'0601020301','0601020302','0601020303','0601020304','0601020305','0601020306','0601020307','0601020308','0601020309','0601020310',
'0601020311','0601020312','0601020313','0601020314','0601020315','0601020316','0601020317','0601020318','0601020319','0601020320',
'0601020321','0601020322','0601020323','0601020324','0601020325','0601020326','0601020327','0601020328','0601020329','0601020330'
);

我已经尝试过这个,但不起作用:

$result = mysql_query("SELECT * FROM test");
if (!$result) {
die('Requête invalide : ' . mysql_error());
}
$a = array();
while ($row = mysql_fetch_assoc($result)) // moi je fais comme ca un mysql_fetch_*
{
$a[] = $row['numero'];
foreach ($a as $val) {
$ret .= "$val";
if ($ret == end($a))
//var_dump($val);
{
//echo "'".$val."'";
}
else
{
echo "'".$val."',";
}
}
}

可能是错误的方法,我之前在这里搜索过,非常感谢。

最佳答案

这应该可以解决问题。您只需根据您的需要调整名称/参数即可。我使用了 json,如果需要的话可以做点别的,或者解码...

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

include"config.inc.php";

$mysqli = mysqli_connect("$host", "$user", "$mdp", "$db");

if (mysqli_connect_errno()) { echo "Error connecting : " . mysqli_connect_error($mysqli); }

$query = " SELECT id_test, name_test, phone_test FROM tbl_tests ";
$stmt = $mysqli->prepare($query);

$results = $stmt->execute();
$stmt->bind_result($id_test, $name_test, $phone_test);
$stmt->store_result();

if ($stmt->num_rows > 0) {
$phones = array();
$phone = array();
while($stmt->fetch()){
echo"[ $id_test -> $name_test -> $phone_test ]<br />";

$phone = "$phone_test";

array_push($phones, $phone);
}
}
else
{ echo"[ no data ]"; }

//print_r($phones);
echo json_encode($phones);

?>

输出:[“00544656347”,“0065465836”,“00656566745”,“0068456868”,“00626565064”]

编辑:由于 mysql_* 在 PHP 5.5 中已被弃用(请参阅 PHP doc ),您应该更喜欢 PPS : Prepared Parameterized Statements 。这将有助于 Preventing SQL injection

关于php - 列出数组 php 中的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43323372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com