Ver Mensaje Individual
  #12 (permalink)  
Antiguo 05/02/2011, 21:37
Malekith
 
Fecha de Ingreso: abril-2006
Mensajes: 105
Antigüedad: 18 años
Puntos: 11
Respuesta: Mostrar a que tema pertenece un artículo determinado

Código PHP:
<?  

//conectamos a la base  
include('conexion.php'); 
//hacemos las consultas  
$result=mysql_query("select * from eventos ORDER BY id_evento DESC LIMIT 1",$connect); 
$row mysql_fetch_array($result);
$id_tema $row["id_tema"]; 

 
$result2 mysql_query("SELECT * FROM temas where id_tema='".$id_tema."'"$connect) or die (mysql_error());
$row2 mysql_fetch_array($result2); 
 
$imagen $row2["imagen"];
 

//Una vez seleccionados los registros los mostramos para su edici�n  
echo '<div style="text-align:center;" class="LeftItem"> 
<a href="index.php?seccion=evento&id='
.$row["id_evento"].'"><img src="'.$imagen.'"  alt="Ultimo evento" width="100" height="141" loop="0" border="0" /></a> 
</div><br/> 
<div class="LeftItem"> 
                    <a href="index.php?seccion=evento&id='
.$row["id_evento"].'"><h4>&nbsp;&nbsp;'.$row[titulo].'</h4></a> 
                    <p class="NewsPost" > 
                        <span class="Block">&nbsp; - Fecha:</span><br/> 
                        <span class="Block">&nbsp; - '
.$row[dia].'</span> 
                    </p> 
                    </div>'
;   


?>
He conseguido que ese código funcione, me muestra la última inserción en la tabla, y también me recoge la ruta de la imagen al tema que pertenece el artículo, me ha costado pero funcionando está.

Ahora un problema... el código anterior en el que hago el array... creía que funcionaba bien, hasta que una vez en funcionamiento el bloque "novedades", el cual siempre está en ejecución en un menú de la web, el array del código anterior me muestra la misma imagen en todos los resultados, el código del array es este:

Código PHP:
<div class="NewsItem"> 
                    <h2 class="NewsTitle"><font size="5">EVENTOS</font></h2><br><br> 
                    <table border="0" height="38" cellpadding="0" cellspacing="0"> 
    <tr> 
        <th height="16" align="left" valign="top"> 
        <p align="left"> 
        <img border="0" src="./images/resumen.jpg" height="24" align="left"></th> 
        <th height="16" align="left" valign="top"> 
        <p align="left"> 
        <img border="0" src="./images/tema.jpg" height="24" align="left"></th> 
        <th height="16" align="left" valign="top"> 
        <p align="left"> 
        <img border="0" src="./images/dia.jpg" height="24" align="left"></th> 
    </tr> 

<?php  
//conectamos a la base   
include('conexion.php'); 

//hacemos las consultas   
$result=mysql_query("select * from eventos order by fecha Desc"$connect);   
$row=mysql_fetch_array($result); 

$id_tema=$row[id_tema]; 
?> 
<? 

$result2
=mysql_query("SELECT * FROM temas where id_tema='$id_tema'"$connect);  
$row2=mysql_fetch_array($result2);  

$imagen=$row2[imagen]; 

?> 
<?php  
//Recogemos las consultas en un array y las mostramos   
while($row=mysql_fetch_array($result))  
{  
   
echo 
'<tr> 
        <td height="19" valign="top" valign="top" background="./images/bg_eventos.jpg"> 
        <a href="index.php?seccion=evento&id='
.$row["id_evento"].'"> 
        <p align="left"><b> - '
.$row["titulo"].':</b><br><br>'.nl2br($row["resumen"]).'</a></td> 
        <td height="19" valign="top" background="./images/bg_eventos.jpg"> 
        <a href="index.php?seccion=evento&id='
.$row["id_evento"].'"> 
        <p align="center"><img border="0" src="'
.$imagen.'" width="50" height="70"></a></td> 
        <td height="19" valign="top" background="./images/bg_eventos.jpg"> 
        <a href="index.php?seccion=evento&id='
.$row["id_evento"].'"> 
        <p align="center"> - '
.$row["dia"].'</p> 
        </a> 
        </td> 
    </tr> 
    <tr> 
        <td height="5" valign="top" valign="top" background="./images/bg_eventos.jpg"> 
        </td> 
        <td height="5" valign="top" background="./images/bg_eventos.jpg"> 
        </td> 
        <td height="5" valign="top" background="./images/bg_eventos.jpg"> 
        </td> 
    </tr> 
'
;  
}  
 
mysql_free_result($result
?></table> 
                </div>
Es decir, va todo perfecto, a excepción de que siempre se repite la imagen que sale en el bloque novedades, esa imagen se pasa al array y en el array todos los resultados son distintos, pero siempre cogen el valor de la imagen que muestra el script de novedades.

Última edición por Malekith; 05/02/2011 a las 21:46