简体   繁体   English

用PHP打印MySQL查询

[英]Printing a MySQL query in PHP

function MattsScript()
{
    $query = 'SELECT * FROM `ACCOUNTING` WHERE  `ACCTSTATUSTYPE` = "start" AND `Process_status` IS NULL LIMIT 0,100';
    $result = mysql_query($query);
    $row = mysql_fetch_assoc($result);

    while ($row = mysql_fetch_assoc($result)) 
    {
        echo $row['USERNAME'] . "<br />";
        echo $row['ACCTSTATUSTYPE'];
    }
}

I am trying to echo the results of a query. 我试图回应查询的结果。 What I think is happening here is I am saving a query to a variable, the first 100 results (LIMIT 0,100) then using a loop to echo each row to the page. 我认为这里发生的是我将查询保存到变量,前100个结果(LIMIT 0,100)然后使用循环将每行回显到页面。

However nothing is happening, no error and nothing written to the page. 但是没有发生任何事情,没有错误,也没有写入页面。

Is there something I am missing? 有什么我想念的吗?

if you are expecting only one result remove the while loop if not leave the while loop and remove the line $row = mysql_fetch_assoc($result); 如果你只期望一个结果删除while循环,如果不离开while循环并删除行$ row = mysql_fetch_assoc($ result); before the while loop. 在while循环之前。 Also make sure you are querying your database correctly. 还要确保正确查询数据库。

Example: $result = mysql_query($query) or die(mysql_error()); 示例: $result = mysql_query($query) or die(mysql_error());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM