我有一个数据库表,该表有6行.我想要的是使用3列和2行表在html页面中显示6行.
我知道如何使用php数组和while循环.我的问题是如何限制数组在第一行放置3个项目,并将另外3个项目放在下一行.
这是我尝试但没有奏效的
<div id="maincontent">
<!-- class one -->
<?php
$getSection = getSection();
$i=0;
while($allSection = mysql_fetch_array($getSection)){
?>
<div class="subconent">
<table width="937" border="0">
<tr>
<td>
<div class="sub_image">
<a href="section.php?id=<?php echo urlencode($allSection['id']); ?>"><img src="admin/uploads/fron_sect/<?php echo $allSection['image']; ?>" width="134" height="120" border="0" alt="HNA" class="PopBoxImageLink" onmouseover="PopEx(this,-50,-25,205,186,20,null);" onclick="window.location='http://localhost/hants/section.php?id=<?php echo urlencode($allSection['id']); ?>'" /></a>
</div>
<div class="cont_txt">
<h3><?php echo $allSection['name_full']; ?></h3>
<p><?php echo substr($allSection['description'],0,140) . ""; ?></p>
<br />
<a href="section.php?id=<?php echo urlencode($allSection['id']); $i++; ?>"><img src="images/read_more.jpg" alt="Read More" width="89" height="25" border="0" /></a>
</div>
</td>
</tr>
</table>
</div> …Run Code Online (Sandbox Code Playgroud) 我在while循环中写出一系列文件,它们被命名
1.dat, 2.dat, 3.dat...
但我需要将数字格式化为 -
00001.dat, 00002.dat, 00003.dat...
Run Code Online (Sandbox Code Playgroud)
读取它们时保持文件顺序.有没有办法改变while循环迭代器的格式?
我正在尝试编写一个while循环,当我选择actres或电影标题时,它存在while循环.但由于某种原因,它不能告诉我,行中有错误while (selecton).有人有想法吗?
string selection;
while ( selection )
{
cin >> selection;
if ( selection == "actress" )
{
cout << "hey" << endl;
break;
}
else if ( selection == "movie title" )
{
cout << "bye";
break;
}
else
{
cout << "Please choose a selection";
}
}
Run Code Online (Sandbox Code Playgroud) 这是一个家庭作业问题,它会问"选择一个字.请用户输入一个字母.检查字母中出现的字母数,然后在屏幕上输出数字." 到目前为止,我已按原样编写,似乎工作正常:
word = str("python")
letters = len(word)
attempt = str(raw_input ("Enter a letter: "))
while attempt in word:
count = "python".count(attempt)
if attempt in word:
print "This letter is present ",count, "time(s)."
attempt = str(raw_input ("Enter another letter: "))
while attempt not in word:
attempt = str(raw_input ("This letter is not present, enter another letter: "))
count = "python".count(attempt)
if attempt in word:
print "This letter is present ",count, "time(s)."
Run Code Online (Sandbox Code Playgroud)
但偶尔如果我输入信件,程序将停止,不再需要更多输入.我究竟做错了什么?如果代码非常草率并且编写得很糟糕,我很抱歉,因为我是编程新手.谢谢.
{
int i=1;
while(i<=32767)
{
printf("%d",i);
i=i+1;
}
}
Run Code Online (Sandbox Code Playgroud)
这似乎是一个简单的程序打印1到32767 ...但当我达到32767 ...在递增值1 .....它试图转到32768,它超出整数范围,并转到另一侧是-32768 .....由于哪个条件变为真,因为我<= 32767即-32768 .....所以它应该作为无限循环工作.我的Dev C++编译器只打印1到32767 ....它不能作为无限循环.任何人
我有一个与while循环相关的奇怪问题.我有一个函数,它在process(print_file())的父元素的末尾被调用,并且它不接受真正的条件继续.这是我简单的多进程代码,如下所示.
#include <stdio.h> /* basic I/O routines. */
#include <stdlib.h>
#include <unistd.h> /* define fork(), etc. */
#include <sys/types.h> /* define pid_t, etc. */
#include <sys/wait.h> /* define wait(), etc. */
#include <signal.h> /* define signal(), etc. */
#include <pthread.h>
#include <time.h>
#include <ctype.h>
void print_file(char* [], char* []);
void child_process(int,int);
void parent_process();
int counter=0;
int main(int argc, char* argv[]) {
counter = atoi(argv[1]);
int i,k;
pid_t child_pid;
int child_status;
char* array[counter];
srand ( time(NULL) ); …Run Code Online (Sandbox Code Playgroud) 我有一段代码循环,直到引发错误或将值None分配给变量"parent".在每个循环中,它将一个值附加到列表,称为actionList.通过print语句,我知道列表在循环的每次迭代中都在增长.但是,在我退出循环后(通过捕获的KeyError),print语句显示该列表现在被赋值为None.知道发生了什么事吗?
while parent is not None:
print "iterating"
print actionList
try:
pathList.append(parentMap[parent])
except KeyError:
break
actionList.append(actionMap[parent])
parent = parentMap.get(parent, None)
return actionList.reverse()
Run Code Online (Sandbox Code Playgroud)
经过进一步检查,一旦我离开循环,看起来动作列表仍然完好无损.但是,当在actionList上使用reverse()方法时,它会消失.我使用reverse()错了吗?
我有这样的函数(parent并且formToBeShown是WinForms表单实例):
if (parent == null)
while (!formToBeShown.IsDisposed)
Do();
else
while (!parent.IsDisposed && !formToBeShown.IsDisposed)
Do();
Run Code Online (Sandbox Code Playgroud)
我发现这些非常不优雅.我很乐意Do只调用一次这个函数.如果我可以将所有条件合并到一个while循环中,那就更好了.不知道我是否有脑屁,但我想不出有办法实现这一点.一些想法?
我正在尝试创建一个小程序,可以判断是否输入了正确的密码,并在输入之前一直询问密码是否正确.正确的密码是'秘密'.
我创建了我的while循环.它将要求输入密码并要求再次输入密码,但无论您是否第一次输入正确的密码,它都会执行此操作.我哪里错了?如果第一次输入正确的密码怎么能让它中断呢?如果正确输入密码,我怎么保持密码?
到目前为止这是我的代码:
password = raw_input('What is the password? ')
correctPassword = 'Secret'
tryAgain = raw_input ('Enter password again ')
password
while password == False:
print 'Enter password again '
if password == correctPassword:
print 'You are in!'
break
Run Code Online (Sandbox Code Playgroud) 我试图仅从String的开头替换非alpanumeric字符.我想出了以下代码:
public static final class FixNonAlphaNumBegin implements PhraseFilter {
@Override
public String filter(String phrase, long frequency) {
int count = 0;
while (!Character.isLetterOrDigit(phrase.codePointAt(count))
&& phrase.length() > count + 1) {
phrase = phrase.replaceFirst(
Pattern.quote(phrase.substring(count, count + 1)), "");
count++;
}
return phrase.trim();
}
}
Run Code Online (Sandbox Code Playgroud)
IndexOutOfBoundsException来自哪里?它应该是不可能的:
例如
String filter = "! "
!Character.isLettorDigit(phrase.codePointAt(0) --> true
phrase.length() > 1 --> true
phrase = phrase.replaceFirst(
Pattern.quote(phrase.substring(0, 0 + 1)), "");
Run Code Online (Sandbox Code Playgroud)
phrase现在" ",count1
!Character.isLettorDigit(phrase.codePointAt(1) --> true
phrase.length() > 2 …Run Code Online (Sandbox Code Playgroud)