Normal Path - Pure PHP:
There are several ways, this is a didactic thing:
$query = mysql_query("SELECT * FROM teste2 ORDER BY id DESC")
or die( mysql_error() );
// usei um contador para você poder testar outras linhas em vez da primeira, se quiser.
$contador = 1;
while ($row = mysql_fetch_array($query)) {
if ( $contador == 1 ) {
echo 'PRIMEIRO - '.$row['teste'];
} else {
echo 'NÃO É O PRIMEIRO - '.$row['teste'];
}
// Aqui, aumentamos o contador a cada linha.
// Se preferir, tire a linha de baixo e ponha o ++ no $contador do if.
$contador++
}
Notice that the solution is fully resolved with PHP. Still with PHP, if it is only the first differentiated line, there is a much simpler alternative:
$query = mysql_query("SELECT * FROM teste2 ORDER BY id DESC")
or die( mysql_error() );
if ( $row = mysql_fetch_array($query) ) {
echo 'PRIMEIRO - '.$row['teste'];
}
while ( $row = mysql_fetch_array($query) ) {
echo 'NÃO É O PRIMEIRO - '.$row['teste'];
}
In this way, the first line is resolved in if
, and if there is more, while
shows the following.
I could have put
while
inside
if
so it would not be used idly if the result came empty, but the gain would be practically null, and the loss of readability immense.
Complicated path - counting lines with MySQL:
If it were necessary to know which line is on the MySQL side, it could be complicated like this:
mysql_query('SET @i = 0'); // inicializamos i
$query = mysql_query('SELECT (@i:=@i+1) AS linha, name FROM teste2 ORDER BY id DESC')
or die( mysql_error() );
while ($row = mysql_fetch_array($query)) {
if ( $row['linha'] == 1 ) {
echo 'PRIMEIRO - '.$row['teste'];
} else {
echo 'NÃO É O PRIMEIRO - '.$row['teste'];
}
}
I have only shown this second way to say that it exists. Avoid it as long as you do not have a real need to count server-side rows. Solutions with pure PHP are appropriate, if the real problem is simple as exposed in the question.
Note that I have changed some things in your syntax, which have nothing to do with the main problem, but which would also hinder your result.