运行此代码时得到空值
$dataArray = mysql_query ("SELECT * from _$symbol order by date DESC limit 10;");
while ($ArrayData = mysql_fetch_assoc($dataArray)) {
$dayData [] = $ArrayData;
}
$todaysdate = $dayData[0]['date'];
$volPercentAVG = $dayData[0]['volume'] / $dayData[0]['_50dayVol'];
mysql_query ("update _$symbol set volPercentAvg=$volPercentAVG WHERE date=$todaysdate;");
它没有返回任何内容,我不确定我是否正确接近MDarray?我已经查了三遍列名。
任何与此相关的地方都将是有益的
谢谢。
@Fred ii-你做到了!我或你能给我一个答案,这样我就可以投票支持它吗?如果可以的话,我不知道怎么做illcrx
发布我的评论作为答案以结束问题。
如果您的date
列包含任何空格或点等,请更改WHERE date=$todaysdate
并引用WHERE date='$todaysdate'
例如:2014-10-06 22:59:52
- 会解释为什么你没有得到结果
然而,我很惊讶/困惑MySQL没有给你带来语法错误,奇怪。
现在没有时间阅读您的全部内容,但我可以从我们的标准mysqli执行集中为您提供我的测试方法:
print_r($Record);
这将使您能够看到结构,并可能看到您的错误所在。
我还会给你我们的框架,它可能非常有用(这就是为什么我们有它!哈哈)。示例框架(两个函数),使在php中更容易使用mysqli,每个查询有两行。它还允许CLI或web输出和调试,这将转储查询(以便您可以运行它),并显示print_r函数以显示结果
这在顶部:
define('DEBUG', false);
define('CLIDISPLAY', false);
if (CLIDISPLAY) {
define('PRE', '');
define('PRE_END', '');
} else {
define('PRE', '<pre>');
define('PRE_END', '</pre>');
}
require_once("/etc/dbconnect.php");
$DBLink = new mysqli($VARDB_server, $VARDB_user, $VARDB_pass, $VARDB_database, $VARDB_port);
if ($DBLink->connect_errno) {
printf(PRE . "Connect failed: %s'n" . PRE_END, $DBLink->connect_error);
exit();
}
请确保在/etc/dbconnect.php中有一个普通的php文件,其中包含您的凭据(不要将这些凭据放在web文件夹中,以防php有一天失败并暴露您的密码!哈哈)。请注意,该文件只能共享和加载一次。它应该调用
# Sample execution
$Query = "select * from vicidial_users where user='6666' and active='Y' limit 1";
$Records = GetData($DBLink, $Query);
print_r($Records[0]); // Single record return access via [0] to access a field named "id": $Records[0]['id']
// Multiple record return access via array walking
foreach ($Records as $Record) {
print_r($Record);
}
$Query = "update vicidial_users set active='Y' where user='6666' limit 1";
UpdateData($DBLink, $Query);
函数(可以从凭证文件或工作文件中加载,也可以放在"Functions.php"文件和"require_one('Functions.php');"中。
function GetData($DBLink, $Query) {
if (DEBUG) {
echo PRE . "Query: $Query'n" . PRE_END;
}
if ($Result = $DBLink->query($Query)) {
if (DEBUG) {
printf(PRE . "Affected rows (Non-Select): %d'n" . PRE_END, $DBLink->affected_rows);
}
while ($Record = $Result->fetch_assoc()) {
$ReturnData[] = $Record;
}
return $ReturnData;
} else {
if (DEBUG) {
printf(PRE . "Errormessage: %s'n", $DBLink->error);
printf("Affected rows (Non-Select): %d'n", $DBLink->affected_rows);
echo "No Records Returned'n" . PRE_END;
}
return false;
}
}
function UpdateData($DBLink, $Query) {
if (DEBUG) {
echo PRE . "Query: $Query'n" . PRE_END;
}
if ($Result = $DBLink->query($Query)) {
if (DEBUG) {
printf(PRE . "%s'n", $DBLink->info);
printf("Affected rows (Non-Select): %d'n" . PRE_END, $DBLink->affected_rows);
}
return;
} else {
if (DEBUG) {
printf(PRE . "Errormessage: %s'n", $DBLink->error);
printf("Affected rows (Non-Select): %d'n", $DBLink->affected_rows);
echo "No Records Returned'n" . PRE_END;
}
return;
}
}