According to your select, the equivalent indices 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 the mysql_fetch_array we can pass a second optional parameter, the result_type which may be the constant MYSQL_BOTH, MYSQL_NUM or MYSQL_ASSOC. If not reported, the value used by default by the function is the 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 value of results, using the standard you double the amount of results stored in the server memory.
These are the little things that influence the performance of your script/application.
To further optimize your script, I advise using PDO to access the database. To work with PHP dates, use the class Datetime that has several functions specific to Date / Time.
theoretically it is only that. To know the
chaves
of the array, of awhile($row = mysql_fetch_array($validade)){ echo '<pre>'; print_r($row);}
– rray
You want to know how to find the date that is to end or how to display the date?
– lionbtt
I just want to show the date you are finishing the person $Name
– ChrisAdler