1

So I have the following:

$query = "SELECT id,account,status FROM service WHERE status = 'Unpaid'";
        $result = mysql_query($query);  

    while($row = mysql_fetch_row($result)){

                $id = $row[0];
                $dateEntered = $row[1];
                $type = $row[2];
                $account = $row[3];
                $dateCompleted = $row[4];
                $notes = $row[5];
                $status = $row[6];

            echo $account;
          // mailStatusUpdate($account, $status, $dateEntered);

        }   

echo mysql_error();

Query processes fine in phpmyadmin. When I echo the $account of the unpaid status records, it doesn't echo. Whats the problem? PHPmyadmin processes everything fine and shows me the records?

2
  • Variable is row[3] and is not empty. Its being defined in the while right above it? Commented Feb 2, 2012 at 16:39
  • 2
    Do a print_r($row); from within the while loop, to see what it says. That will let you know what you're working with. Commented Feb 2, 2012 at 16:39

2 Answers 2

4

You're only retrieving three columns from the query.

$account should be set to $account = $row[1];

$status should be set to $status = $row[2];

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

2 Comments

yeah, that the true answer. Just noticed it and you've posted it, great job ;)
Tim, your answer is partly correct. I did what another guy said, the connection wasn't set up properly for some reason. Thank you for your help i appreciate it!
0

You are only selecting 3 fields(id (0),account (1), status(2) ) so $account=$row[1] will echo account; There is no $row[3]. If you want to get all the columns use SELECT * FROM service WHERE.....

also to fetch values, use keys

    $query = "SELECT * FROM service WHERE status = 'Unpaid'";
    $result = mysql_query($query);  

       while($row = mysql_fetch_assoc($result)){

            $id = $row['id'];
            $dateEntered = $row['dateEntered'];
            $type = $row['type'];
            $account = $row['account'];
            $dateCompleted = $row['dateCompleted'];
            $notes = $row['notes'];
            $status = $row['status'];

        echo $account;
      // mailStatusUpdate($account, $status, $dateEntered);

    }   

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.