我试着去创建一个函数,将返回一个MySQL查询,我可以再遍历和处理的结果,但它似乎没有奏效.我甚至可能不会以正确的方式这样做.
function GetAccounts($username){
require("dbconn.php");
$result = mysql_query("SELECT * FROM `accounts` WHERE `username` = '$username' ") or trigger_error(mysql_error());
return "$result";
}
$result = GetAccounts($username);
while($row = mysql_fetch_array($result)){
foreach($row AS $key => $value) { $row[$key] = stripslashes($value); }
$theusername = $row['theusername'];
$thepassword = $row['thepassword'];
echo $theusername;
}
Run Code Online (Sandbox Code Playgroud)
我收到的错误是
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Run Code Online (Sandbox Code Playgroud)
我尝试将上述所有内容加载到函数中,但每次都只能返回一个结果.由于生病需要处理每个结果,我"想"上面的方式是我想要做的,但让我知道是否有更好的方法,或我做错了什么.
当我使用用户名回显函数时,我得到以下内容;
Resource id #5
Run Code Online (Sandbox Code Playgroud) 运行以下程序将打印"空间溢出:当前大小8388608字节".我已经读过这个和这个,但仍然不知道如何解决我的问题.我正在使用foldr,不应该保证它是"尾递归"吗?
到目前为止,我对Haskell感觉很棒,直到我知道在使用强大的递归时我应该防止"空间溢出".:)
module Main where
import Data.List
value a b =
let l = length $ takeWhile (isPrime) $ map (\n->n^2 + a * n + b) [0..]
in (l, a ,b)
euler27 = let tuple_list = [value a b | a <-[-999..999] , b <- [-999..999]]
in foldr (\(n,a,b) (max,v) -> if n > max then (n , a * b) else (max ,v) ) (0,0) tuple_list
main = print euler27
Run Code Online (Sandbox Code Playgroud)
编辑:isPrime为简单起见删除定义
我想在Cocoa应用程序中提交以下URL并将结果保存为字符串(尽管XML可能更好):
http://translate.google.com/translate_t#en|fr|hi%20there%20all
Run Code Online (Sandbox Code Playgroud)
该页面不断返回错误.这是我的代码:
NSString *urlString = @"http://translate.google.com/translate_t#en|fr|hi%20there%20all";
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10];
NSData *urlData;
NSURLResponse *response;
NSError *error;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
NSString *content = [[NSString alloc] initWithBytes:[urlData bytes]
Run Code Online (Sandbox Code Playgroud)
以上导致URL变为:
http://translate.google.com/translate_t%23en%7Cfr%7Chi%2520there%2520all
Run Code Online (Sandbox Code Playgroud)
这导致了来自Google的404.如果我在没有转义的情况下尝试URL,我会返回零字节.关于如何使这项工作的任何想法?
---编辑---
问题的根源是url的值为nil.删除EscapesUsingEncoding行(第2行)并检查url的值.我在URL中的管道导致[NSURL URLWithString:urlString]; 返回零.使用十六进制值转义管道7C(http://translate.google.com/translate_t#en%7cfr%7chi%20there%20all)返回数据.但是我在NSString*内容行上再次获得零字节.
我遇到了一个问题,可能是由于我对DateTime.ToShortTimeString()方法如何工作的误解.使用此函数格式化时间字符串时,我假设它将遵循Windows 7格式设置中的"短时间"设置
Control Panel -> Clock, Language and Region -> Region and Language -> Formats Tab.
然而,.NET似乎选择了一种不基于此设置的短时间格式,而是基于当前的文化:
Region and Language -> Location -> Current Location
我在Windows 7 RC上做了一些测试:
Culture: en-GB, 6AM: 06:00, 6PM: 18:00 // HH:mm (United Kingdom) Culture: en-GB, 6AM: 06:00, 6PM: 18:00 // hh:mm (United Kingdom) Culture: en-US, 6AM: 6:00 AM, 6PM: 6:00 PM // HH:mm (United States) Culture: en-US, 6AM: 6:00 AM, 6PM: 6:00 PM // hh:mm (United States) Culture: el-GR, 6AM: 6:00 ??, 6PM: 6:00 ?? …
有谁知道我将用什么MySQL语句返回包含数据库中所有表的列表的结果以及每个表中的行数?
我有一个JS函数,用于轮询iframe中的当前url,目的是确定iframe是否指向与主文档相同的站点.因此,代码基本上是:
function urlCheck()
{
var location = document.getElementById('frameid').contentWindow.location.href;
if (location)
{
// iframe src is currently local
}
else
{
// iframe src is currently not local
}
}
Run Code Online (Sandbox Code Playgroud)
从功能上讲,这段代码非常有效.但是,在错误控制台中,每次调用此函数并且iframe src不是本地时,我都会收到错误:
Permission denied for [site1] to get property Location.href from [site 2]
如何修复代码以避免这些错误?
谢谢,麻辣
是否有针对Chrome的条件评论这样的事情?
与Firefox相比,我在Chrome中的页面呈现方式不同.
谢谢
WPF XAML,我有一个我写的自定义控件包装查找.在典型的政府方式中,他们有一个查找表,可以查找所有可能的查找.我的自定义控件将抛出一个弹出式叠加层,要求他们从列表中的项目中进行选择.我的问题特别涉及从我的调用表单到我的控件属性到我的底层控制VM的数据绑定.
我正在调用这样的控件:
<Controls:LookupSelector SelectedLookupValueId="{Binding Path=DataContext.SelectedHarvestMethod, ElementName=SurveyFormWindow, Mode=TwoWay}" />
Run Code Online (Sandbox Code Playgroud)
(已删除其他垃圾邮件)在这种情况下,需要显式DataContext,因为控件的实际datacontext是其自己的视图模型.SelectedHarvestMethod是ViewModel表单上的属性.
它在"新窗体"模式下工作,控件负责设置自己的值(控件包含一个按钮,当您单击它时,会弹出一个按钮,您可以选择所需的查找数据值).这就像我说的那样工作正常,甚至可以回到上面代码中的'SelectedHarvestMethod'.我可以使用这个并且确信我的ViewModel总是将选定的id分配给该属性.
但现在我正在进行"编辑现有表单"模式,我从数据库加载数据并在视图模型中设置属性.所以我设置'SelectedHarvestMethod'并且代码工作正常(在setter中命中断点)但是'SelectedLookupValueId'上的结果setter没有被调用 - 值永远不会通过.
'SelectedLookupValueId'是控件视图模型上的DP:
public static readonly DependencyProperty SelectedLookupValueIdProperty =
DependencyProperty.Register("SelectedLookupValueId", typeof(int), typeof(LookupSelector), new UIPropertyMetadata(0));
public int SelectedLookupValueId
{
get { return (int) GetValue(SelectedLookupValueIdProperty); }
set { SetValue(SelectedLookupValueIdProperty, value); ViewModel.SetPreSelectedLookupValueId(value); }
}
Run Code Online (Sandbox Code Playgroud)
输出窗口或事件日志中没有错误或写在我的鞋底.插入的调试转换器显示绝对分配了整数值.正如评论中所提到的,VM当然会实现INotifyPropertyChanged,并且正在提升事件.
此外,实际类型是"用户控制",而不是自定义控件:它涉及XAML.
为什么不调用我的控件的属性设置器?
我想重写以下网址:
类似于 - 内容/添加 - 内容/编辑
我也使用预填充模型,并希望能够重写此URL:
对于这样的事情:
这可能吗?如果是这样,我是否需要一些Drupal模块,或者我是否必须接受htaccess文件?
php ×3
mysql ×2
.htaccess ×1
.net ×1
c# ×1
cocoa ×1
css ×1
cultureinfo ×1
database ×1
datetime ×1
drupal ×1
drupal-6 ×1
firefox ×1
formatting ×1
forms ×1
haskell ×1
iframe ×1
javascript ×1
mvvm ×1
objective-c ×1
properties ×1
recursion ×1
time ×1
wpf ×1