Title: MySQL Statement not echoing variable in while
Tags: php;mysql
Question: 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?
Comment: Variable is row[3] and is not empty. Its being defined in the while right above it?

Comment: 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.

Here is the accepted answer: 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];
Comment for this answer: 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!
Comment for this answer: yeah, that the true answer. Just noticed it and you've posted it, great job ;)

Here is another answer: 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);
}

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:02/02/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><mysql>', 'Title': 'MySQL Statement not echoing variable in while', 'ViewCount': 47, 'id': 9116118, 'user_AboutMe': '', 'user_AccountId': 350591.0, 'user_DisplayName': 'JD Audi', 'user_Reputation': 1057.0, 'user_Views': 123.0, 'user_id': 686581.0}}