the function doesn't know your database!
This is because of how function works: they just know the variables you submit to the function and the variables you defined as global.
If you want to use the database within the function, use global to get information about the database - quite difficult to explain but i give you the example so that you should be able to imagine what i mean 😉
function listar() {
// this makes the variables global so that the function can use them!
global $HTTP_GET_VARS, $noticias;
$id = $HTTP_GET_VARS['idn'];
$query_detalhenoticia = "SELECT * FROM noticias WHERE id = '$id'";
$detalhenoticia = mysql_query($query_detalhenoticia, $noticias) or die(mysql_error());
$row_detalhenoticia = mysql_fetch_assoc($detalhenoticia);
$totalRows_detalhenoticia = mysql_num_rows($detalhenoticia);
$data = $row_detalhenoticia['data'];
$resumo = $row_detalhenoticia['resumo'];
$titulo = $row_detalhenoticia['titulo'];
$noticia = $row_detalhenoticia['noticia'];
echo $data . " " . $resumo . " " . $titulo . " " . $noticia;
}
by the way:
Why do you use a function?
Just do it as an if-command:
....
if (isset ($HTTP_GET_VARS['idn']))
{
$id = $HTTP_GET_VARS['idn'];
$query_detalhenoticia = "SELECT * FROM noticias WHERE id = '$id'";
$detalhenoticia = mysql_query($query_detalhenoticia, $noticias) or die(mysql_error());
$row_detalhenoticia = mysql_fetch_assoc($detalhenoticia);
$totalRows_detalhenoticia = mysql_num_rows($detalhenoticia);
$data = $row_detalhenoticia['data'];
$resumo = $row_detalhenoticia['resumo'];
$titulo = $row_detalhenoticia['titulo'];
$noticia = $row_detalhenoticia['noticia'];
echo $data . " " . $resumo . " " . $titulo . " " . $noticia;
}
else
{
....
hope that helps 😉