我正在从 MYSQL 数据库中进行选择,我需要将所有选定的记录以如下格式传递给一个数组: 数组
(
[1] => Weather today is rubbish
[2] => This cake looks amazing
[3] => His skills are mediocre
[4] => He is very talented
[5] => She is seemingly very agressive
[6] => Marie was enthusiastic about the upcoming trip. Her brother was also passionate about her leaving - he would finally have the house for himself.
[7] => To be or not to be?
)
我希望自动生成 key 并分配给每条记录。
这是我的代码:
$conn = new mysqli($servername, $username, $password, $dbname);
$SQLCommand = "SELECT fback FROM feedback";
$result = mysqli_query($conn, $SQLCommand);
$i = 1;
$query = mysqli_query($conn, 'SELECT fback FROM feedback');
$tot = mysqli_num_rows($query);
echo '<br/>You are having <b style="color:red;">' . $tot . '</b> tasks to do.<br/><br/>';
while($a = mysqli_fetch_array($query))
{
echo $i++ . '. ' . $a[0] . '<br/>';
}$featured = array();
foreach($featured as $key => $value){
echo $a;
}
最佳答案
你是这个意思吗?
$featured = array();
$count = 1;
while($a = mysqli_fetch_array($query)) {
$featured[$count] = $a[0];
$count++;
}
print_r($featured);
关于php - 使用格式化的键和值将所有 MYSQL 记录传递到数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43678506/