while循环只显示一行 [英] While loop only displaying one row

查看:781
本文介绍了while循环只显示一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML表单,允许用户从员工列表中进行选择。变量是'$ empfullname。'但是,我也希望他们能够选择一个'全部'选项,如果选择它应该采取第一个雇员,并运行PHP脚本,然后采取下一步,等等等等。但是,如果选择全部,我现在的代码只显示表中的第一名员工并停止。也许我也需要一个foreach吗?任何帮助是极大的赞赏。 ($ empfullname =='All'){
$ query =select * from。

  $ db_prefix。employee order by empfullname asc; 
$ result = mysql_query($ query);
} else {
print timecard_html($ empfullname,$ local_timestamp_in_week);

$ b $ while($ row = mysql_fetch_array($ result)){
print timecard_html(stripslashes(。$ row ['empfullname']。),$ local_timestamp_in_week);



解决方案

循环不在if语句中,请试试:

  if($ empfullname =='All'){
$ query =select * from。$ db_prefix。employee order by empfullname asc;
$ result = mysql_query($ query);

while($ row = mysql_fetch_array($ result)){
print timecard_html(stripslashes(。$ row ['empfullname']。),$ local_timestamp_in_week);



else {
print timecard_html($ empfullname,$ local_timestamp_in_week);

$ / code>

另外,我不会使用与员工全名相同的变量检查是否选择了全部)。


I have an HTML form that allows the user to select from a list of employees. The variable is '$empfullname.' However, I also want them to be able to select an 'All' option and if selected it should take the first employee and run the PHP script, then take the next, and so on and so forth. However, the code I have right now if 'All' is selected just displays the first employee in the table and stops. Maybe I need a foreach in their as well? Any help is greatly appreciated. Thanks.

if ($empfullname == 'All') {
    $query = "select * from ".$db_prefix."employees order by empfullname asc";
    $result = mysql_query($query);
} else {
    print timecard_html($empfullname, $local_timestamp_in_week);
}

while ($row=mysql_fetch_array($result)) {
    print timecard_html(stripslashes("".$row['empfullname'].""), $local_timestamp_in_week);

}

解决方案

Your while loop isn't within the if statement, try:

if ($empfullname == 'All') {
    $query = "select * from ".$db_prefix."employees order by empfullname asc";
    $result = mysql_query($query);

    while ($row=mysql_fetch_array($result)) {
         print timecard_html(stripslashes("".$row['empfullname'].""),    $local_timestamp_in_week);
    }
} 

else {
    print timecard_html($empfullname, $local_timestamp_in_week);
}

Also, I wouldn't use the same variable as the Employee's Full Name to check if 'All' is selected ;).

这篇关于while循环只显示一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆