我试图进行动态划分,用变量更改其id.除此之外,dvision是一个弹出窗口.该部门必须是独一无二的,因为我从数据库中提取信息.到目前为止我所拥有的是:
<?php
$index_map = 4; //this variable is already defined in other part of the document.
//It is just here to specify its value to the readers
$index_data = 1;
while($index_data = $index_map)
{
echo '
<div data-role="popup" id="mapdata'.$index_data.'" class="ui-content" data-theme="d">
<img class="popphoto" src="style/2nd_floor.png"
style="max-height:512px;" alt="Parking_Lot_Map1">
'.$index_data.'
</div>
';
$index_data++;
}
?>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,while循环不执行任何操作,并且在此之后不显示任何其他html数据.这是一个包含在另一个.php文件中的PHP文档.我不知道为什么while循环不识别变量
如果我的代码出现问题,我会提前道歉; 我还是很陌生.
我做了一个简单的小RNG投注游戏,其中包括:
var funds = 100;
var betting = true;
function roll_dice() {
var player = Math.floor(Math.random() * 100);
var com = Math.floor(Math.random() * 100);
var bet = prompt("How much do you bet? Enter a number between 1 and " + funds + " without the $ sign.");
if (player === com) {
alert("tie.");
}
else if (bet > funds) {
alert("You don't have that much money. Please try again");
roll_dice();
}
else if (player > com) {
funds …Run Code Online (Sandbox Code Playgroud) 我想在C代码中做的是检查用户输入并验证他们只能输入"一个"或"两个".我做了一个while循环,检查用户输入值strcmp,但它不起作用.while循环似乎忽略了getchar();并且进行了无限循环.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char choice[80];
while(strcmp (choice,"one") != 0 || strcmp (choice,"two") != 0){
scanf("%s", &choice);
getchar();
}
// if the user enters either one or two, continue executing code...
return 0;
}
Run Code Online (Sandbox Code Playgroud) 好吧,我正在建立一个游戏网站,我有一个搜索栏,用户输入他想要找到的游戏.我有这样的东西(这是一个测试,不需要阻止SQL注入):
<?php
if ($_REQUEST['search']){
$searched = $_POST['searched'];
$gamesearched = mysql_query("SELECT * from games WHERE name like '%$searched%'");
while($write=mysql_fetch_array($gamesearched)){
echo "Found it!"
}
}else{
echo "Search something";
}
?>
Run Code Online (Sandbox Code Playgroud)
我不能在while语句中使用else,所以我该如何显示"没有找到游戏"的内容.
我试图使用它但不起作用:P
while(($write=mysql_fetch_array($gamesearched)) != null){
echo "found";
}else{
echo "not found";
}
Run Code Online (Sandbox Code Playgroud) 我有以下while循环,如果我在while循环条件中放入this.boatTripsList.iterator().hasNext(),则抛出错误.当我创建迭代器然后放入while循环条件时,它将工作.为什么是这样?感谢和问候.(第二个版本抛出错误)
public Journey(List<BoatTrip> trips) {
this.boatTripsList = new LinkedList<BoatTrip>();
Iterator<BoatTrip> iterator = trips.iterator();
//add the given boat trips to the boattrips list
while (iterator.hasNext()) {
BoatTrip thistrip = iterator.next();
this.boatTripsList.add(thistrip);
}
}
public Journey(List<BoatTrip> trips) {
this.boatTripsList = new LinkedList<BoatTrip>();
//add the given boat trips to the boattrips list
while (trips.iterator().hasNext()) {
BoatTrip thistrip = iterator.next();
this.boatTripsList.add(thistrip);
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下代码,一切似乎工作除了while循环,这里是代码:
JLabel img = new JLabel(loadingScreens.getImageIcon(0));
loadingFrame.setUndecorated(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double width = screenSize.getWidth();
double height = screenSize.getHeight();
int wid = (int) width;
int hgt = (int) height;
wid = wid/2;
hgt = hgt/2;
wid -=350;
hgt -=350;
loadingFrame.setLocation(wid, hgt);
loadingFrame.setSize(700, 700);
loadingFrame.setBackground(new Color(0,0,0,0));
loadingFrame.add(img);
loadingFrame.setIconImage(loadingScreens.getImage(0));
loadingFrame.setVisible(true);
System.out.println("Done 1");
try{
Thread.sleep(500);
System.out.println("Done 2");
}catch(Exception e){
System.out.println("exception caught");
}
Integer lo = 0;
System.out.println("Done 3");
while(lo.equals(256)){
System.out.println("Started 4");
loadingFrame.setBackground(new Color(lo, lo, lo, lo));
loadingFrame.repaint();
try{
Thread.sleep(10);
}catch(Exception e2){ …Run Code Online (Sandbox Code Playgroud) 我使用此代码显示管理员用户:
<?php
while($write = mysql_fetch_array(mysql_query("SELECT * from users WHERE level >1"))){
echo ''.$write['username'].'';
}
?>
Run Code Online (Sandbox Code Playgroud)
但页面永远保持加载!这有什么问题?
我需要C#循环的帮助.循环需要做什么:
xt = 50
现在程序需要等待时间(x = 50),每秒递减一次.如果实际时间为0,程序需要发送我的请求并设置xt = 50.所以循环可以重新开始,所有这一段代码都应检查每50秒向服务器发送一个请求.
我的实际代码:
while (xt != 0)
{
xt--;
Thread.Sleep(1000);
Console.WriteLine ("bla:"+ xt);
}
if (xt == 0)
{
Console.WriteLine("Ich sende!");
//post.SendPost(randomengine.decodeb64(URL2),"Alive");//richtige Daten eintragen! Idiot!
xt = 50;
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个'Euromillions彩票发生器'只是为了好玩,我不断打印出相同的数字.我该如何制作它以便我得到随机数字并且永远不会弹出相同的数字:
from random import randint
numbers = randint(1,50)
stars = randint(1,11)
print "Your lucky numbers are: ", numbers, numbers, numbers, numbers, numbers
print "Your lucky stars are: " , stars, stars
Run Code Online (Sandbox Code Playgroud)
输出只是:
>>> Your lucky numbers are: 41 41 41 41 41
>>> Your lucky stars are: 8 8
>>> Good bye!
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
问候
为了测试我的技能,我正在尝试编写自己的几个标准库函数版本.我写了一个替代strlen(),strlength():
int strlength(const char *c){
int len = 0;
while (*c != '\0') {
c++;
len++;
}
return len;
}
Run Code Online (Sandbox Code Playgroud)
其中不包括null-terminator,我正在尝试编写一个函数来反转字符串.这个:
char *reverse(const char *s){
char *str = (char *)malloc(sizeof(char) * strlength(s));
int i = 0;
while (i < strlength(s)) {
str[i] = s[(strlength(s) - 1) - i];
i++;
}
str[strlength(s)] = '\0';
return str;
}
Run Code Online (Sandbox Code Playgroud)
适用于每个字符串,除了一个包含32个字符(不包括null-terminator)之类的字符串foofoofoofoofoofoofoofoofoofoofo.它挂在reverse()函数while循环中.对于所有其他数量的字符,它的工作原理.为什么会这样?
while-loop ×10
loops ×3
php ×3
c ×2
if-statement ×2
java ×2
mysql ×2
c# ×1
int ×1
iterator ×1
javascript ×1
python ×1
random ×1
strcmp ×1
string ×1