我有一个输出类列表的while循环.在类数据库中,教师名称由用户数据库中的教师ID确定.
这是我的数据库结构.
Classes Database
-----------------------------
ID CLASS TEACHER
1 product design 3
User Database
-----------------------------
ID NAME
3 John Doe
Run Code Online (Sandbox Code Playgroud)
因此,当列出我的类时,我需要它将"3"转换为"John Doe".
这是我目前的代码:
<?php
$classdetails = mysql_query("SELECT * FROM class");
while($class = mysql_fetch_array($classdetails)) {
$marklist_class = $class['class'];
$marklist_teacher = $class['teacher']; //This is a userid
//------Somewhere here i need to get the userid and look it up in the user database
if($marklist_class=="") {
} else {
echo $marklist_class . ' ' . $marklist_teacher;}
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我理解只是放入另一个mysql查询会降低性能并且不建议,所以如何在不向while循环中添加查询的情况下查找每行的用户数据库.
谢谢.
我正在使用一个位于(例如)a StreamReader或者顶部的界面SqlDataReader.接口公开一个方法,GetNext()如果有任何对象,或者null如果没有剩下,则返回一个对象.
public interface ICollectionWidget<T>
{
T GetNext(); // Returns a T if there are any left, or null if there aren't
}
Run Code Online (Sandbox Code Playgroud)
我需要并行处理每个T返回的GetNext(),并在GetNext()返回时停止处理 null.我不太确定这是怎么做的(使用TPL或其他).我需要一种平行while!显然,我不希望任何线程仍然处理完成,当我得到一个null,我只是不想添加任何新的处理 - 然后当所有线程完成他们正在做的事情时退出'循环' .
有人可以帮忙吗?如果我的问题没有意义,请告诉我.
为什么可以使用while循环读取文件,例如
while (file >> variable)
Run Code Online (Sandbox Code Playgroud)
要么
while (getline(xx, yy))
Run Code Online (Sandbox Code Playgroud)
执行>>和getline函数返回布尔值?
我目前正在将无限循环中的数据写入覆盆子pi上的SD卡.
file = open("file.txt", "w")
while True:
file.write( DATA )
Run Code Online (Sandbox Code Playgroud)
似乎有时如果程序没有通过命令或键盘中断关闭,file.txt并不总是保存.是否有定期的方法来保存并确保数据被保存?我在考虑使用
open("file.txt", "a")
Run Code Online (Sandbox Code Playgroud)
附加到文件并定期关闭txt文件并再次打开它.在运行无限循环时,有更好的方法可以安全地存储数据吗?
我正在阅读有关如何编程网络套接字并运行这段代码的内容:
try {
while (true) { // This is the line in question
int i = in.read( );
if (i == -1) break;
System.out.write(i);
}
}
catch (SocketException e) {
// output thread closed the socket
}
catch (IOException e) {
System.err.println(e);
}
Run Code Online (Sandbox Code Playgroud)
第二行如何知道何时失败?换句话说,while(true)循环如何工作?我想我不明白'虽然这是真的吗?'
通过定义存储单元
struct node {
int item;
node *next;
};
Run Code Online (Sandbox Code Playgroud)
假设ptr指向一个链表,那么put while(ptr!=NULL) 和 while(ptr->next!=NULL)循环通过列表之间是否有区别,直到到达空指针?
我有一个while循环,简化如下:
while read -r line
do
(delete some lines from file2.txt)
done < file.txt
Run Code Online (Sandbox Code Playgroud)
如果file2.txt为空,则此while循环不再需要运行.
换句话说,我需要这个:
while read -r line AND file2.txt IS NOT EMPTY
do
(delete some lines from file2.txt
done < file.txt
Run Code Online (Sandbox Code Playgroud)
我试着结合while read -r line使用-s file2.txt,但结果不工作:
while [ read -r line ] || [ -s file2.txt ]
do
(delete some lines from file2.txt)
done < file.txt
Run Code Online (Sandbox Code Playgroud)
如何使用while循环读取文件中的行,同时还检查另一个文件是否为空?
我正在尝试memmove在Rust中实现标准函数,我想知道哪种方法对于向下迭代更快(其中src< dest):
for i in (0..n).rev() {
//Do copying
}
Run Code Online (Sandbox Code Playgroud)
要么
let mut i = n;
while i != 0 {
i -= 1;
// Do copying
}
Run Code Online (Sandbox Code Playgroud)
将rev()在for环版本显著慢下来?
我无法在lisp中使用简单的while循环!
(loop (while (row >= 0))
setf(row (- row 1))
(collect (findIndex row col))
Run Code Online (Sandbox Code Playgroud)
当row大于或等于0时,我想减少行并收集findIndex方法给出的结果.假设给出了col.
谢谢!!!
编1:
#include<stdio.h>
int main()
{
int i=0;
while(i<=8,i++);
printf("%d",i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编2:
#include<stdio.h>
int main()
{
int i=0;
while(i++,i<=8);
printf("%d",i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Prog 1的输出为1,而Prog 2的输出为9。
有人可以解释一下这里发生了什么。两种代码有何不同?
while-loop ×10
c++ ×2
loops ×2
bash ×1
c ×1
c# ×1
comma ×1
common-lisp ×1
database ×1
file ×1
for-loop ×1
java ×1
linked-list ×1
lisp ×1
memmove ×1
mysql ×1
php ×1
python ×1
raspberry-pi ×1
rust ×1