我对此比较陌生,如果我在错误的地方发帖,那就很抱歉.我在我的数据库中有一个表,它包含4个东西 - id,时间输入和用户和消息(用于基本的聊天室风格的东西).我正在尝试使用PHP页面调用它们.但是当我在地址栏中输入一个参数时,我的页面才会返回空白.我试图调用它,以便只显示用户列中具有特定用户的行.我的代码在下面 - 任何人都可以看到我做错了什么?该文件的URL是http://freedom-apps.co.uk/chat/messages.php.你会看到一大堆条目 - 一开始就有umumu m.U表示用户输入,m表示消息.所以我尝试了:http: //freedom-apps.co.uk/chat/messages.php?user = u ,它返回一个错误.有任何想法吗?我的代码是:
<?php
header( 'Content-type: text/xml' );
mysql_connect('localhost:/var/lib/mysql/mysql.sock',
'freedom_ASAPPS', '********');
mysql_select_db( 'freedom_chat_alpha' );
if ( $_REQUEST['user'] ) {
$user = mysql_escape_string($_REQUEST['user']);
$result = mysql_query('SELECT * FROM chatitems WHERE user = '$user'
ORDER BY added LIMIT 50');
} else {
$result = mysql_query('SELECT * FROM chatitems ORDER BY added LIMIT 50');
}
?>
<chat>
<?php
while ($row = mysql_fetch_assoc($result)) {
?>
<message added="<?php echo( $row['added'] ) ?>" …Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习python并不断得到一个我无法弄清楚的错误.任何帮助都将受到大力赞赏.基本上,我不断收到以下错误:
Enter an int: 8
Traceback (most recent call last):
File "C:\Users\Samuel\Documents\Python Stuff\Find Prime Factors of Number.py", line 16, in <module>
once_cycle()
File "C:\Users\Samuel\Documents\Python Stuff\Find Prime Factors of Number.py", line 8, in once_cycle
while x==0:
UnboundLocalError: local variable 'x' referenced before assignment
Run Code Online (Sandbox Code Playgroud)
我看到很多人都有同样的问题,但当我看到人们告诉他们要做的事情时,我无法理解.无论如何,我的代码是这样的.我已经重新检查了所有缩进,并且看不出它的问题.这个程序的目的是找到一个int的主要因素(虽然它只有90%完成).它是用Python 2.7.3编写的.
import math
testedInt = float(raw_input("Enter an int: "))
workingInt = testedInt
x = 0
def once_cycle():
for dividor in range(1, int(math.floor(math.sqrt(testedInt))+1)):
while x==0:
print "Called"
if (workingInt%dividor == 0):
workingInt = workingInt/dividor
x = 1
if …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行此代码,以便它为列表的所有元素运行一个函数.为了说明的目的,基本上它应该打印:
'----------Possible Word:', possible_word
Run Code Online (Sandbox Code Playgroud)
对于我列表中的所有项目.因此,如果我输入['p','r','s'],它将运行该打印3次,每个项目一次.我的代码如下 - 当我运行它时它只运行p和s,而不是r,这真的很奇怪.有任何想法吗?
def check_matches(input):
print 'Input:', input
for possible_word in input:
print '----------Possible Word:', possible_word
valid = True
for real_word in word_dictionary:
possible_word_list = list(possible_word)
real_word_list = list(real_word)
print possible_word_list
print real_word_list
number_of_characters_to_check = len(possible_word_list)
for x in range(0, number_of_characters_to_check):
print possible_word_list[x] + real_word_list[x]
if (possible_word_list[x] != real_word_list[x]):
valid = False
if (valid == False):
input.remove(possible_word)
print all_possible
return input
Run Code Online (Sandbox Code Playgroud) 我在视图控制器中有一个 NSButton,当单击它时,应该调用另一个类的实例中的方法(我在视图控制器中有该实例)。但是,永远不会调用操作方法。
我的代码如下(简短而简单)。请有人能解释一下这是为什么吗?
使用按钮查看控制器类:
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let b:NSButton = NSButton(frame: NSRect(x: 150, y: 200, width: 30, height: 30))
self.view.addSubview(b)
let g = Global()
b.target = g
b.action = #selector(g.s)
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个名为“Global”的类的实例,然后按钮应该调用其中的方法:
class Global:NSObject {
override init() {
super.init()
}
@objc dynamic func s() {
Swift.print("S ran")
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢
更新:为了方便重现,我创建了一个 GitHub 存储库,在此处以最简单的形式显示了该问题。
C得到一个小问题.限制自己使用简单的C(即操作系统指令),两个字符串似乎不一样.这是我的代码:
char inputData[256];
int rid;
rid = read(0,inputData,256);
// Strip input
char command[rid];
int i;
for (i = 0; i<=rid-2; i++) {
command[i] = inputData[i];
}
command[rid-1] = '\0';
if (command == "exit") {
write(1,"exit",sizeof("exit"));
}
Run Code Online (Sandbox Code Playgroud)
现在,如果用户在查询时进入"退出"并且点击进入,则检测到"退出"的if永远不会运行.有任何想法吗?
谢谢,
编辑:我在去的时候提交git,所以当前的版本可以在github.com/samheather/octo-os找到.这显然不是完整的代码,但它证明了这个问题.