[英]Fatal error: Class '2' not found in
I am getting two columns from llamadas where idLlamadas is the primary key, I want to get these values so I can use them later but when I try to use the primary key on $v ... I am getting this error: Fatal error: Class '2' not found in ...
I did some tests and it looks like the '2' is a value in idLlamadas, it gives me the same error if it is 1, 2, 3, 4, etc. it conflicts with the first value. 我从llamadas得到两列,其中idLlamadas是主键,我想获取这些值,以便以后可以使用它们,但是当我尝试在$ v上使用主键时,我得到此错误:
Fatal error: Class '2' not found in ...
我做了一些测试,它看起来像'2'是idLlamadas中的值,如果它是1、2、3、4等,它给我同样的错误。第一个值。
code: 码:
$q = ("SELECT idLlamadas, comentarios FROM llamadas");
$sql = mysqli_query($con, $q);
foreach ($sql->fetch_all() as $k => $v){
var_dump ($k);
var_dump ($v);
$comentario = $v(0);
}
The way you're accessing this data, $v
should be an array containing [idLlamadas, comentarios] for each iteration. 访问此数据的方式,
$v
应该是一个包含[idLlamadas,comentarios]的数组,用于每次迭代。 You're currently trying to execute it like a function or class constructor, which will cause PHP to fail as it is currently. 您当前正在尝试像函数或类构造函数一样执行它,这将导致PHP失败。
However, mysqli_result->fetch_all()
is a very resource hungry way of retrieving data from the database. 但是,
mysqli_result->fetch_all()
是从数据库中检索数据的非常mysqli_result->fetch_all()
资源的方法。 I recommend you restructure your code as follows: 我建议您按以下方式重组代码:
$sql = 'SELECT `idLlamadas`, `comentarios` FROM `llamadas`';
$result = mysqli_query($con, $sql);
if ($result) {
while ($row = mysqli_fetch_assoc($result)) {
var_dump($row); // outputs array('idLlamadas' => 1, 'comentarios' => 'No somos tortugas.')
// You can get the id with $row['idLlamadas']
// Or the comment with $row['comentarios']
}
} else {
print('MySQLi error: [' . mysqli_errno($con) . '] ' . mysqli_error($con));
}
The error comes from $comentario = $v(0);
错误来自
$comentario = $v(0);
. 。
$v
is an array, and if you want to get the value of idLlamadas
, then use $v[0]
but not $v(0)
. $v
是一个数组,如果要获取idLlamadas
的值, idLlamadas
使用$v[0]
而不是$v(0)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.