我有以下工作代码查询外while循环,使用循环的内部,一点儿也不工作
$notchDetails = mysqli_query($conn, "SELECT * FROM notches WHERE projectid = ".$projectid." LIMIT ".$offset.", ".$limit."");
// i want $query here //
$outp3 = "[";
if (mysqli_num_rows($notchDetails) > 0) {
while($notch = mysqli_fetch_assoc($notchDetails)) {
$query = mysqli_query($conn, "DESCRIBE $table");
$count = count($notch);
$allnotches[] = $notch["notchid"]; // $allnotches is needed further in script //
if ($outp3 != "[") {$outp3 .= ",";}
$outp3 .= "{";
$x = 1;
while ($rs = mysqli_fetch_assoc($query)) {
$field = $rs["Field"];
$outp3 .= '"'.$field.'":"'.$notch[$field].'"';
if ($x != $count) { $outp3 .= ","; }
$x++;
}
$outp3 .= "}";
}
}
$outp3 .="]";
(不要看的变数名称缺口,could'nt找到更好的翻译比缺口它的复杂;-))
问题解释说:
当我把$query = mysqli_query...
while循环(略低于$notchDetails = mysqli_query...
)外,
只得到1分的结果,其余的在空:while ($rs = mysqli_fetch_assoc($query)) { //result// }
房颤据我所看到的,它应该与$查询工作在循环之上。但我不明白为什么它不是。
有人可以解释为什么这不起作用吗?
P.s.将其置于循环之外的原因是性能/速度
我是否正确地创建了JSON结构? –
没错。我需要将多个JSON放入1个文本文档(使用序列化,然后对其进行加密)。你有更好的解决方案吗? –
是的。 json_encode() –