prova a togliere MYSQL_NUM

res = mysql_query($query);
while ($riga = mysql_fetch_array($res)) {
echo "ciao";