According to your select , equivalent indexes are:
-
0 equivalent to Name
-
1 equivalent to data1
-
2 equivalent to data2
-
3 equivalent to data3
-
4 equivalent to data4
Assuming the connection to the bank is already established. The code would be:
sql = ("SELECT Nome, data1, data2, data3, data4 < (now()+ interval 10 day)");
$validade = mysql_query($sql);
while($row = mysql_fetch_array($validade))
{
$nome = $row[0];
$prazo = $row[1]; // Ou o índice da data que desejar acessar
$mensagem = "<body><p><strong>Faltam menos de 10 dias para terminar $Nome.</strong></p>" .
"<p>Prazo: $prazo</p></body>";
$PHPMailer = new PHPMailer();
(....)
$PHPMailer->Body = $mensagem;
}
If you prefer to use the field name to capture the data, do:
$nome = $row['Nome'];
$prazo = $row['data1']; // Ou o nome do campo da data que desejar acessar
Remembering that when we use mysql_fetch_array we can pass an optional second parameter, result_type which can be the MYSQL_BOTH , MYSQL_NUM or MYSQL_ASSOC . If not informed, the value used by default by the function is MYSQL_BOTH .
Examples of how your result would come (I used random values):
// Usando MYSQL_BOTH
array (size=10)
0 => string 'nome capturado' (length=14)
1 => string '2013-12-20' (length=10)
2 => string '2014-01-20' (length=10)
3 => string '2014-02-20' (length=10)
4 => string '2014-03-20' (length=10)
'Nome' => string 'nome capturado' (length=14)
'data1' => string '2013-12-20' (length=10)
'data2' => string '2014-01-20' (length=10)
'data3' => string '2014-02-20' (length=10)
'data4' => string '2014-03-20' (length=10)
// Usando MYSQL_NUM
array (size=10)
0 => string 'nome capturado' (length=14)
1 => string '2013-12-20' (length=10)
2 => string '2014-01-20' (length=10)
3 => string '2014-02-20' (length=10)
4 => string '2014-03-20' (length=10)
// Usando MYSQL_ASSOC
array (size=10)
'Nome' => string 'nome capturado' (length=14)
'data1' => string '2013-12-20' (length=10)
'data2' => string '2014-01-20' (length=10)
'data3' => string '2014-02-20' (length=10)
'data4' => string '2014-03-20' (length=10)
Imagine that you return a high result value, by default you double the amount of results stored in server memory.
It's these little things that influence the performance of your script / application.
To further optimize your script, I advise you to use PDO to access the database of data. To work with dates in PHP, use the class DateTime that has several Date / Time specific functions .