标签: while-loop

两个相同的while循环函数,第二个不起作用

我的php脚本有问题.该脚本生成两个<ul>,一个带有图像,另一个带有缩略图.php完美地运行第一个while循环,但我<ul>的缩略图总是空回来.我一直在努力工作,没有运气,我似乎无法让脚本打印任何错误.救命?

include "../backend/connect.php";
$query = "select image_id from images where thumb != '';";
$result = mysql_query($query);
<div id="main">
    <div id="container">
        <ul>
            <?php
            while ($row = mysql_fetch_array($result)) {
                $img_id = $row['image_id'];
            ?>
            <li class="hidden" id="<?php print($img_id); ?>" style="background-image:url(/pull.php?id=<?php print($img_id);?>&thumb=false)"></li>
            <?php } ?>
            <li class="" id="focus"></li>
        </ul>
    </div>
</div>
<div id="side">
    <div id="photos"><ul>
    <?php
    while ($row = mysql_fetch_array($result)) {
        $img_id = $row['image_id'];
    ?>
        <div class="imgDiv" id="<?php print($img_id); ?>" >
            <li>
                <img src="pull.php?id=<?php print($img_id);?>&thumb=true" class="thumbnail"/>

            </li>
        </div>
    <?php
        } …
Run Code Online (Sandbox Code Playgroud)

php while-loop

0
推荐指数
1
解决办法
558
查看次数

MYSQL在mysql_query数组中定义某些列?

当我从多个共享列名的表中进行选择时,我可以返回两者,但是定义哪一个我想从中选择数据?

例如:两个表都包含"日期"列,我想同时使用这两个列,但我希望避免重命名具有重复名称的每个列.

 $query = mysql_query("SELECT * FROM posts, comments"); //(SELECT * is just for example)
 while($row=mysql_fetch_array($query))
 {
     $postDate = $row['date'];  //I would like to be able to do something like:
                                //$postDate = $row['posts']['date']; OR $row['posts.date'];
                                //of course it's all in an array now, jumbled up.
     $commentDate = $row['date']; 
 }
Run Code Online (Sandbox Code Playgroud)

php mysql while-loop

0
推荐指数
1
解决办法
355
查看次数

c#中的Hashset给出了一种奇怪的行为

我在C#中遇到HashSet问题....

这是我的代码:

  List<int> elements = new List<int>();
        for(int i = 0;i< 100000;i++)
        {
            elements.Add(i);
        }
        HashSet<int> c = new HashSet<int>();
        foreach(var ele in elements)
        {
        c.Add(ele);
        }

        Console.WriteLine("Working HashSet " + c.Count);

        var Numbers = new HashSet<int>();
        var mycount = 0;
        using (TextReader reader = File.OpenText(@"myfile.txt"))
        {
            while ((line = reader.ReadLine()) != null)
            {
                mycount++;
                int parsed = int.Parse(line);
                Numbers.Add(parsed);
            }
        }

        Console.WriteLine("my counter took" + mycount);

        Console.WriteLine("Bad HashSet" + Numbers.Count);
Run Code Online (Sandbox Code Playgroud)

工作HashSet 100 000

我的柜台拿了50万

Bad HashSet 9999

为什么第二个hashset没有添加50万个项目???? 这对我来说是个谜

c# memory-management hashset while-loop data-structures

0
推荐指数
1
解决办法
187
查看次数

Shell虽然循环没有停止

我正在编写一个例程来识别进程是否停止运行,并且一旦目标进程消失就会执行某些操作.

我想出了这段代码(作为我未来代码的测试):

#!/bin/bash
value="aaa"
ls | grep $value
while [ $? = 0 ]; 
    do
    sleep 5
    ls | grep $value
    echo $?
done;
echo DONE
Run Code Online (Sandbox Code Playgroud)

我的问题是,由于某种原因,循环永远不会停止,并在删除文件"aaa"后回显1.

0
0    >>> I delete the file at that point (in another terminal)
1
1
1
1
.
.
    .
Run Code Online (Sandbox Code Playgroud)

我删除文件后,我希望输出为"DONE"...

有什么问题?

解:

#!/bin/bash
value="aaa"
ls | grep $value
while [ $? = 0 ];
    do
    sleep 5
    ls | grep $value
done;
echo DONE
Run Code Online (Sandbox Code Playgroud)

bash shell while-loop

0
推荐指数
1
解决办法
3875
查看次数

而在VB.NET中循环

我有一些语法问题.我习惯了C#,刚刚开始使用VB.NET.我试图while循环从列表中的项目循环.我做错了什么语法?

While oResponse.outputControl.Items(i) <> Nothing

    //Do something

End While
Run Code Online (Sandbox Code Playgroud)

vb.net while-loop

0
推荐指数
1
解决办法
4505
查看次数

Jquery setTimeout循环同时

我的非常简单的循环虽然不起作用,但似乎问题来自setTimeout.我尝试用倒计时编写一个小游戏.

while ( there is time ) {
  // actions possible to do

  //my timer function
}
Run Code Online (Sandbox Code Playgroud)

所以,如果c是时间

var c = 30;

while (c > 0)
{ 
c -= 1;      
setTimeout( $("#timer").html(c) , 1000);   
};
Run Code Online (Sandbox Code Playgroud)

它不仅仅是倒计时,而且用户必须能够在倒计时期间采取行动.谢谢你的帮助 !

jquery while-loop settimeout

0
推荐指数
1
解决办法
1万
查看次数

Objective-C每天在给定时间执行方法 - 杂乱的实现

我有以下(可见)方法不断检查当前时间,并且当达到特定时间(在这种情况下是午夜)时,NSLog语句运行一次以表示正在执行的有用的事情:

- (void) checkTime {

while (true){

    NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];

    NSDate *now = [[NSDate alloc] init];

    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
    [outputFormatter setDateFormat:@"HH:mm"];

    NSString *nowDateString = [outputFormatter stringFromDate:now];

    if([nowDateString isEqualToString:@"00:00"]){
        NSLog(@"Store previous days data..");
        BOOL stillMidnight = YES;
        while(stillMidnight == YES){
            NSDate *latestNow = [[NSDate alloc] init];

            NSDateFormatter *latestOutputFormatter = [[NSDateFormatter alloc] init];
            [latestOutputFormatter setDateFormat:@"HH:mm"];

            NSString *latestString = [latestOutputFormatter stringFromDate:latestNow];
            //Check if it is still midnight
            if([latestString isEqualToString:@"00:01"]){
                //leave while
                stillMidnight = NO;
            }
        }
        NSLog(@"No …
Run Code Online (Sandbox Code Playgroud)

iphone multithreading timer objective-c while-loop

0
推荐指数
1
解决办法
2467
查看次数

php和mysql查询麻烦 - 查询无效

我正在尝试创建一个用户表,这是一个组的一部分,但我似乎无法让它工作.该列表存储在一列中,以便每个用户ID#由"〜"分隔.例如,如果用户1,2和3正在参加该列将显示"1~2~3".这就是我用来爆炸的东西.

我收到以下错误"警告:mysql_fetch_array()期望参数1是资源,布尔值在"哪个是定义$ friend的行.

$attendingUsers = mysql_query("Select acceptedInvites from events where eventID = ".$_GET['eventID']." ");
    while($friend = mysql_fetch_array($attendingUsers)){
                $users = $friend['acceptedInvites'];
                $userExplode = explode("~",$users);
            for($i=0; $i<count($userExplode);$i++){
                echo $userExplode[$i]; //displays the userid number properly so I know this is working
                $friendInfo = mysql_query("select (userid,username) from users where userid = '". $userExplode[$i]."' ");;
                $friend = mysql_fetch_array($friendInfo);
                echo '<table><tr><td><a href="profile.php?userid=' . $friend['userid'] . '">' . $friend['username'] . '</a></td>';
                }
            }
Run Code Online (Sandbox Code Playgroud)

我开始认为它与$ friendInfo有关,因为当我回显它时,没有显示任何内容(通常会说数组).

php mysql for-loop while-loop

0
推荐指数
1
解决办法
72
查看次数

为什么此代码会出现"无法访问的语句"错误?

这是我的代码,我得到一个无法访问的语句错误,但我不知道为什么.

public boolean Boardload(String[] args) throws Exception
{
    Robot robot = new Robot();
    Color color3 = new Color(114, 46, 33);
    Color color4 = new Color(180, 0, 0);

    {
        Rectangle rectangle = new Rectangle(0, 0, 1365, 770);

        {
            while(false)
            {
                BufferedImage image = robot.createScreenCapture(rectangle);
                search: for(int x = 0; x < rectangle.getWidth(); x++)
                {
                    for(int y = 0; y < rectangle.getHeight(); y++)
                    {
                        if(image.getRGB(x, y) == color3.getRGB())
                        {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }
} 
Run Code Online (Sandbox Code Playgroud)

确切的错误是:

java:68: …
Run Code Online (Sandbox Code Playgroud)

java loops while-loop unreachable-code

0
推荐指数
1
解决办法
4362
查看次数

while循环语法错误意外结束文件

我的while循环有语法错误,我的代码如下

#! /bin/bash
# extracts pdb from mdcrd and fix number and move to one central location

filename="min_8a-"
i=1
num_structures=1000
natoms=97
folders=15



while [[ $i -le $folders ]]; do
 cd ~/new/sa/na-main/a-na-main/second/$i
 mkdir pdbfit

x=1

 while [[ $x -le $num_structures ]]; do

   ptraj ./8a-${a}.prmtop << EOF
   trajin $filename$a.mdcrd $x $x 1
   trajout pdbfit/a-2-$i.pdb pdb dumpq
 EOF
 let x=$x+1
 done

 cd pdbfit 
 mv *.* ~/pdbfit
 cd ..
 rm pdbfit

let i=$i+1
done
Run Code Online (Sandbox Code Playgroud)

我得到第34行语法错误,指出"语法错误:意外的文件结束"

作为一个未经训练的眼睛,我尝试但未能解决这个问题,所以如果有人可以帮助我,那么这将是伟大的.

syntax bash syntax-error while-loop

0
推荐指数
1
解决办法
2835
查看次数