如何在php多维数组中处理来自mysql的数据

如何在php多维数组中处理来自mysql的数据,php,mysql,Php,Mysql,我运行此代码时得到空值 $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][

我运行此代码时得到空值

$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?我已经三次检查了列名

任何与此相关的地方都会有帮助


谢谢

现在没有时间阅读您的全部内容,但我可以从我们的标准mysqli执行集为您提供我的测试方法:

print_r($Record);
这将允许您查看结构以及错误所在的位置

我也会给你我们的框架,这可能是非常有用的(这就是为什么我们有它!哈哈)。示例框架(两个函数),使在php中使用mysqli更容易,每个查询有两行。它还允许CLI或web输出和调试,这将转储查询(以便您可以运行查询),并显示打印功能以显示结果:

这是在顶部:

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();
}
函数(可以从凭证文件或工作文件中加载,也可以放入“Functions.php”文件和“require_once('Functions.php');”

@弗雷德二世-你做到了!我或你能回答这个问题,这样我就可以投赞成票吗?如果我能,我不知道怎么做

发布我的评论作为答案,以结束问题

如果您的
date
列包含任何空格或点等,则更改
WHERE date=$todaysdate

到/并引用它
WHERE date='$todaysdate'


例如:
2014-10-06 22:59:52

  • 会解释为什么你没有得到结果

然而,bizarro,我很惊讶/困惑MySQL并没有向您抛出语法错误。

好吧,如果
var\u dump($ArrayData)
不返回任何内容,然后
从$symbol order by date DESC limit 10中选择*;
不返回任何内容。您是否在phpMyAdmin中尝试过该查询?在查询周围使用单引号以抑制
$
就地展开。双引号内的
$symbol
将替换为
$symbol
变量的值,该变量为appa请保留为空。请。它们不再被维护,而是。改为了解,并使用or。这将帮助您决定。为什么要在
中使用下划线作为
符号
?如果
日期
包含任何空格或点等。然后尝试将
WHERE date=$todaysdate
更改为/并引用
WHERE date='$todaysdate'
您不知道没有时间读10行,但你有时间写100行。没有时间读你的答案,但投了反对票,因为它显然没有回答OP的问题。
我也会给你我们的框架
我想你对框架的定义不清楚……我不是为这篇文章写的。那是从we每天都使用。这不涉及破译别人的代码,而是作为一个工具,让他破译自己的代码。试图帮助他在php/mysql中完成他的旅程。因此,我因为尝试帮助而得到了一个降价。就框架而言:它有一个顶部部分(设置调试等参数)和底部部分(函数!)然后对这些函数执行示例,可以删除未使用的部分。最后,SQL查询可以使用两行代码和所有功能运行&可选的DEBUG.Framework。
# 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);
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;
    }
}