Ir para conteúdo
Fórum Script Brasil
  • 0

Ajuda em script php


locgames

Pergunta

Bom comprei um curso q ensina a fazer um portal de noticas so q ele apenas coloca na pagina principal a ultima noticia cadastrada, e gostaria de coloca mais de uma noticias na pgina principal

Ex:

1° Noticias

2° Noticias

3° noticas..

<?php require_once('Connections/connDB.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_connDB, $connDB);
$query_rsUltimaNoticia = "SELECT n.intNotID, n.strNotTitle, n.strNotText, n.strNotImage, n.intNotViews, n.strNotDateCad, c.strCatTitle, u.strUsrName FROM pn_noticias AS n INNER JOIN pn_noticias_categorias AS c ON n.intCatID = c.intCatID INNER JOIN pn_usuarios AS u ON n.intUsrID = u.intUsrID WHERE n.strNotStatus = 'on' AND n.strNotHome = 'yes' ORDER BY n.intNotID DESC";
$rsUltimaNoticia = mysql_query($query_rsUltimaNoticia, $connDB) or die(mysql_error());
$row_rsUltimaNoticia = mysql_fetch_assoc($rsUltimaNoticia);
$totalRows_rsUltimaNoticia = mysql_num_rows($rsUltimaNoticia);

mysql_select_db($database_connDB, $connDB);
$query_rsUltimasNoticias = "SELECT intNotID, strNotTitle FROM pn_noticias WHERE intNotID <> {$row_rsUltimaNoticia['intNotID']} ORDER BY intNotID DESC LIMIT 5";
$rsUltimasNoticias = mysql_query($query_rsUltimasNoticias, $connDB) or die(mysql_error());
$row_rsUltimasNoticias = mysql_fetch_assoc($rsUltimasNoticias);
$totalRows_rsUltimasNoticias = mysql_num_rows($rsUltimasNoticias);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="alternate" type="application/rss+xml" title="Feed RSS das notícias recentes" href="http://endereco-site.com.br/rss.php" />
<title>Portal de Notícia</title>
</head>

<body>
<h1><?php echo $row_rsUltimaNoticia['strNotTitle']; ?></h1>
<p><?php echo date( 'd/m/Y H:i', strtotime($row_rsUltimaNoticia['strNotDateCad'])); ?> por <?php echo $row_rsUltimaNoticia['strUsrName']; ?> em <?php echo $row_rsUltimaNoticia['strCatTitle']; ?></p>
<?php if ( file_exists( 'fotos-noticias/' . str_replace( '.jpg', '.thumb.jpg', $row_rsUltimaNoticia['strNotImage'])) ) : ?>
<p><img src="fotos-noticias/<?php echo str_replace( '.jpg', '.thumb.jpg', $row_rsUltimaNoticia['strNotImage']); ?>" alt="<?php echo $row_rsUltimaNoticia['strNotText']; ?>" /></p>
<?php else : ?>
<p><img src="fotos-noticias/sem-foto.jpg" alt="" /></p>
<?php endif; ?>
<p><?php echo $row_rsUltimaNoticia['strNotText']; ?></p>
<p><a href="noticia.php?intNotID=<?php echo $row_rsUltimaNoticia['intNotID']; ?>">Comente esta notícia</a></p>

<h2>Últimas notícias</h2>

<ol>
    <?php do { ?>
        <li><a href="noticia.php?intNotID=<?php echo $row_rsUltimasNoticias['intNotID']; ?>"><?php echo $row_rsUltimasNoticias['strNotTitle']; ?></a></li>
    <?php } while ($row_rsUltimasNoticias = mysql_fetch_assoc($rsUltimasNoticias)); ?>
</ol>

</body>
</html>
<?php
mysql_free_result($rsUltimaNoticia);

mysql_free_result($rsUltimasNoticias);
?>
já tentei de todas as maneiras q imaginei, so não achei ao certo aonde que ele diz q so a ultima noticias deve ir na home se alguém puder ajudar agradeço desde já Bom pelo q eu estava lendo é esta opção
ORDER BY n.intNotID DESC";

q faz com quem so a ultima noticia seja exibida na pagina principal alguém teria alguma ideia como posso substituir ela? porque ate onde eu olhei order by ou pode ser apenas desc, ou asce

plz uma ajudinha ai já to fikando com cabelo branco :)

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

Puts nunca vi tanto join para fazer uma coisa tão simples.

$n=$_GET['n']; // resgata parametro de url
$r="SELECT * FROM n ORDER BY n.intNotID DESC LIMIT".$n;  // limita os resultados do banco ao paramentro de url
$q=mysql_query($r);

while($l = mysql_fetch_assoc($q)){
echo $l['strNotTitle']; // exibe dados em laço
}

/* if($_GET['n']<1){
header("location: ".$_SERVER['PHP_SELF']."?n=5");
}
*/

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...