1
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.

However nothing is happening, no error and nothing written to the page.

Is there something I am missing?

5
  • 2
    Are you sure tha tyou have error reporting turned on? Are you sure that MattsScript gets called? Commented Apr 3, 2013 at 22:36
  • Are you sure that fields names USERNAME and ACCTSTATUSTYPE exists? Commented Apr 3, 2013 at 22:37
  • The first result is ignored due to $row = mysql_fetch_assoc($result); right after mysql_query; are you sure you have multiple results ? Commented Apr 3, 2013 at 22:39
  • Oh, and you're doing mysql_fetch_assoc twice. No need for the first one. Commented Apr 3, 2013 at 22:53
  • Find example here: w3schools.com/php/php_mysql_select.asp Commented Apr 3, 2013 at 22:54

1 Answer 1

3

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); before the while loop. Also make sure you are querying your database correctly.

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.