Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/08/2011, 19:37
Avatar de eadladm
eadladm
 
Fecha de Ingreso: julio-2011
Mensajes: 6
Antigüedad: 12 años, 9 meses
Puntos: 0
problema a identificar campos en mysql

Hola a todos, estoy haciendo un sistema de noticia que se pueda ver en la pagina inicio la noticia un titulo, categoría y descripción y que este tenga un link leer mas para que te muestre todo la noticia.

Yo he estado intentando pero no logro poner el leer mas, lo coloco pero solo la primera fila de datos en la tabla de la base de datos me identifica. Este es el código que he echo asta ahora.

index.php
Código PHP:
<?php
 
include("funciones.php");

cabecera();

cuerpo();

$cont conexion_db();
mysql_select_db("web");
$sql "select * from noticias order by id_noticia desc limit 5";
$resultado mysql_query($sql) or die(mysql_error());

if(isset(
$_GET["noticia"]))
{
    
$dato mysql_fetch_array($resultado);
     if(
$_GET["noticia"] == id_noticias($_GET["noticia"])){
         
             echo 
"
               <table border=\"2px\">
                <tr>
                 <td width=\"500px\">
                  "
.$dato["titulo"]."
                 </td>
                </tr>
                <tr>
                 <td height=\"200px\">
                 "
.$dato["cuerpo"]."
                 </td>
                </tr>
               </table>
               "
;
         }
         else{
              echo 
"No se encuentra nada";
             }
    }
else{
      while (
$dato mysql_fetch_array($resultado)){
    echo 
"<table border=\"1px\">
            <tr>
            <td>
             <img src="
.$dato["imagen"]." width=\"60px\" height=\"60px\" />
            </td>
            <br />
             <td width=\"500px\">
              <b>Titulo</b><br />"
.$dato["titulo"]."<div style=\"float: right;\"><b>Categoria:</b><a href=\"".$_SERVER["PHP_SELF"]."?categoria=".$dato["categoria"]."\">".$dato["categoria"]."</a><br /></div><br />
             <hr />
             "
.$dato["descripcion"]."<br />
             <a href=\""
.$_SERVER["PHP_SELF"]."?noticia=".$dato["id_noticia"]."\">Leer M&aacute;s</a>
             </td>
           </tr>
          </table>"
;
    }
    
    }
echo 
mysql_error();
pie();
?>
funciones.php

Código PHP:
function conexion_db()
{
    
mysql_connect("localhost","foro","mundo123");    
}

function 
cabecera()
{
 echo 
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <title>Web de prueba</title>
     <link href="estilo/estilo.css" rel="stylesheet" />
     </head>
     <body>
       <div id="contenedor">
        <div id="cabecera">
         <div class="cb-po">
          <h1>Natural Forest</h1>
         </div>
        <div class="cb-menu-ps">
         <ul class="cb-menu">
          <li><a href="index.php">Portada</a> |</li>
          <li><a href="insertar.php">Insertar anuncio</a> |</li>
          <li><a href="contactanos.php">Contactanos</a> |</li>
          <li><a href="noticias.php">Noticias</a> |</li>
          <li><a href="FAQ.php">FAQ</a> </li>
          </ul>
        </div>
       </div>'
;    
}
function 
cuerpo ()
{
      echo 
'<div id="cuerpo">';
}
function 
pie()
{
    echo 
'</div>
          <div class="pie">
          <p>Diseñado por SayDead</p>
         </div>
        </div>
        </body>
       </html>'
;
}
function 
id_noticias($id)
{
    
$sql "select * from noticias where id_noticia=".$id;
    
$rs mysql_query($sql);
    
$fila mysql_fetch_array($rs);
    return 
$fila["id_noticia"];
    }
?> 
insertar.php

Código PHP:
<?php

include("funciones.php");

cabecera();

cuerpo();
if(!
$_POST){
        echo 
"<div>
              <form method=\"post\" action="
.$_SERVER["PHP_SELF"].">
               <b>Nombre</b><br />
               <input type=\"text\" name=\"titulo\" /> <b>Categor&iacute;a</b> 
               <select name=\"categoria\">
                <option value=\"PS Vita\">PS Vita</option>
                <option value=\"Video\">Videos</option>
                <option value=\"Analisis\">Analisis</option>
               </select><br />
               <b>Titulo Descriptivo</b><br />
               <input type=\"text\" name=\"descripcion\" /><br />
               <b>Imagen inicial</b><br />
               <input type=\"text\" name=\"imagen_inicial\" /><br />
               <b>Contenido</b><br />
               <textarea name=\"contenido\" cols=\"60\" rows=\"8\"></textarea><br /><br />
               <div align=\"center\"><input type=\"submit\" value=\"Enviar\" class=\"boton\" /></div>
               </form>
               </div>
               "
;
          }
else{
        
$conectar conxion_db();
                    
mysql_select_db("web");
                    
mysql_query("insert into noticias(titulo,categoria,cuerpo,imagen,descripcion) values('".$_POST["titulo"]."','".$_POST["categoria"]."','".$_POST["contenido"]."','".$_POST["imagen_inicial"]."','".$_POST["descripcion"]."')");
        echo 
mysql_error();
        
        echo 
"<div class=\"ok\">
               Noticia publicada correctamente
              </div>"
;
    }
pie();
Espero que me entiendan, gracias por su ayuda.