0

I can output the CSV perfectly when $values = mysql_query("SELECT * FROM ".$table."");

However when I try to select specific columns I have as for example in

$values = mysql_query("SELECT email, status FROM ".$table."");

I get the following error

Notice: Undefined offset: 1 (goes until N-1 fields I have) Warning: Cannot modify header information - headers already sent by

Could you guys advise please?

Code Lღver
  • 15,573
  • 16
  • 56
  • 75

2 Answers2

0

This is NOT Headers already sent question. This error is just a consequence of another error.
Of course an error message causes headers to be sent.
But fix the error and both messages will be gone.

Nevertheless, "Undefined offset" error is second most popular question on Stackoverflow. Though, most likely it is caused by another error in turn.

Most likely you're using old ugly mysql_result() to get mysql data.
And do not check for mysql errors.
Do your mysql this way

$sql = "SELECT email, status FROM ".$table;
$res = mysql_query($sql) or trigger_error(mysql_error(),"[$sql]");
while ($row = mysql_fetch_array()) {
    echo $row['name']; // assuming "name" field in the data
}
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
0

Notice: Undefined offset: 1

Is the only error occurring here really. If this:

$values = mysql_query("SELECT email, status FROM ".$table."");

fails and:

$values = mysql_query("SELECT * FROM ".$table."");

succeed, it's most likely that you are spelling the fields name wrong and therefore the query is failing, returning a non array resource like false.

Warning: Cannot modify header information - headers already sent by

is just a consequence of the first error being printed out.

Shoe
  • 74,840
  • 36
  • 166
  • 272