gpt4 book ai didi

php - Mysql 行放入数组 PHP

转载 作者:行者123 更新时间:2023-11-29 23:17:30 25 4
gpt4 key购买 nike

这个问题已经被问过很多次了,但我真的不明白如何做到这一点。

我正在尝试将整行的值插入到 PHP 的数组中。查询结果如下:

+-----+-----+------+------+------+------+------+-----+
+ Ln1 + Ln2 + Mar1 + Mar2 + Mar3 + Mer1 + Mer2 + Mer3+
+-----+-----+------+------+------+------+------+-----+
+ 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
+-----+-----+------+------+------+------+------+-----+

我想将所有这些“1”插入到名为 $giorni 的数组中,实际上我正在使用

$arr_prep= array("Ln1","Ln2","Mar1","Mar2","Mar3","Mer1","Mer2","Mer3");
$giorni = array();

for($c = 0; $c < 8; $c++){

$temp = mysql_fetch_array(mysql_query("SELECT '$arr_prep[$c]' FROM Corsi WHERE id='$id'"));
array_push($giorni,$temp);

}

结果打印为"echo "giorni -->".array_values($giorni);"是:

giorni -->Arraygiorni -->Arraygiorni -->Arraygiorni -->Arraygiorni -->Arraygiorni -->Arraygiorni -->Arraygiorni -->Array

我也尝试过 mysql_fetch_arraymysql_fetch_row ,也许我以错误的方式使用它们,但我无法让它工作。谁能建议我该怎么做?谢谢

最佳答案

Code Example

Try Changing SELECT '$arr_prep[$c]' FROM... to SELECT $arr_prep[$c] FROM..

删除“”

你会得到输出为数组 ( [0] => 1 1 => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 1 [6] => 1 [7] => 1 )

关于php - Mysql 行放入数组 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27634688/

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