Tengo en una base de datos dos tablas, en ambas existe la columna Id, que identifica un Inmueble.
La primera tabla contiene datos sobre el mismo y la segunda fotos. Lo que quiero es obtener todos los datos del mismo en un array y todas las fotos. Aquí va el código:
Código PHP:
$conexion = mysql_connect('BLA') or die(mysql_error());
mysql_select_db($base,$conexion) or die(mysql_error());
$query = "SELECT * FROM $tabla, $tabla2 WHERE ($tabla.Id='$varid' AND $tabla2.Id='$varid')";
$pegar=mysql_query($query, $conexion) or die($query.' :'.mysql_error());
?>
<html>
<head>
<?php
while($row = mysql_fetch_array($pegar))
{
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Referencia
:</b></font></td>
<td width="68%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
<? echo $row['Id']; ?>
</font></td>
</tr>
<tr>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Tipo
:</b></font></td>
<td width="68%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
<? echo $row['Tipo']; ?>
</font></td>
</tr>
<tr>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Localidad
:</b></font></td>
<td width="68%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
<? echo $row['Localidad']; ?>
</font></td>
</tr>
<tr>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Zona
:</b></font></td>
<td width="68%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
<? echo $row['Zona']; ?>
</font></td>
</tr>
<tr>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Habitaciones
:</b></font></td>
<td width="68%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><? echo $row['Habitaciones']; ?></font></td>
</tr>
<tr>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Baños
:</b></font></td>
<td width="68%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><? echo $row['Banyos']; ?></font></td>
</tr>
<tr>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Superficie
:</b></font></td>
<td width="68%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><? echo $row['Superficie']; ?>
m2 </font></td>
</tr>
<tr>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Precio
:</b></font></td>
<td width="68%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><? echo $row['Precio']; ?>
€</font></td>
</tr>
</table>
</td>
<td height="311" width="42%" valign="top" rowspan="2">
<table width="85%" border="0" cellspacing="0" cellpadding="0" align="center" bordercolor="#E9E9E9">
<tr>
<td height="2" bgcolor="#CCCC00" colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><img src="images/1nada.gif" width="5" height="9"><b>Fotos
</b></font></td>
<td bgcolor="#CCCC00" valign="top" width="38%">
<div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><img src="images/1nada.gif" width="5" height="9"></font><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF"><b><font size="2"><img src="images/eskina_u_right.gif" width="5" align="top"></font></b></font></div>
</td>
</tr>
<tr>
<td colspan="2" height="2"><img src="images/1nada.gif" width="50" height="5"></td>
<td width="38%" height="2"><img src="images/1nada.gif" width="50" height="5"></td>
</tr>
<tr>
<td height="2" colspan="3">
<table border="0" cellspacing="0" cellpadding="0" align="center" bordercolor="#E9E9E9" width="100%">
<tr bgcolor="#E9E9E9">
<td bgcolor="#E9E9E9" height="23" colspan="2">
<div align="center"><a href="#"><img src="fotos/<? echo $row['foto1']; ?>" width="100" height="100" border="2"></a></div>
</td>
<td height="23" width="50%">
<div align="center"><a href="#"><img src="fotos/<? echo $row['foto2']; ?>" width="100" height="100" border="2"></a></div>
</td>
</tr>
<tr bgcolor="#E9E9E9">
<td height="2" bgcolor="#E9E9E9" colspan="2">
<div align="center"><img src="images/1nada.gif" width="50" height="5"></div>
</td>
<td height="2" width="50%">
<div align="center"><img src="images/1nada.gif" width="50" height="5"></div>
</td>
</tr>
<tr bgcolor="#E9E9E9">
<td bgcolor="#E9E9E9" height="100" colspan="2">
<div align="center"><a href="#"><img src="fotos/<? echo $row['foto1']; ?>" width="100" height="100" border="2"></a></div>
</td>
<td height="100" width="50%">
<div align="center"><a href="#"><img src="fotos/<? echo $row['foto1']; ?>" width="100" height="100" border="2"></a></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="2" colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><img src="images/1nada.gif" width="5" height="9"></font></td>
<td height="2" width="38%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><img src="images/1nada.gif" width="5" height="9"></font></td>
</tr>
<tr>
<td width="46%" bgcolor="#CCCC00" height="4"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><img src="images/1nada.gif" width="5" height="9"><b>Descripcion</b></font></td>
<td width="16%" bgcolor="#CCCC00" height="4" valign="top">
<div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF"><b><font size="2"><img src="images/eskina_u_right.gif" width="5" align="top"></font></b></font></div>
</td>
<td height="4" width="38%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><img src="images/1nada.gif" width="5" height="9"></font></td>
</tr>
<tr valign="top" align="right" bgcolor="#E9E9E9">
<td colspan="3"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF"><b><font size="2"><img src="images/eskina_u_right.gif" width="5" align="top"></font></b></font></td>
</tr>
<tr bgcolor="#E9E9E9">
<td colspan="3" height="4"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row['Descripcion']; ?></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="57%" valign="bottom">
<table border="0" cellspacing="0" cellpadding="0" width="75%" align="center">
<tr>
<td colspan="2" height="2">
<div>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td bgcolor="#CCCC00" width="98%">
<div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Caracteristicas</b></font></div>
</td>
<td valign="top" bgcolor="#CCCC00" width="2%">
<div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF"><b><font size="2"><img src="images/eskina_u_right.gif" width="5" align="top"></font></b></font></div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td width="52%" bgcolor="#E9E9E9" height="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><img src="images/1nada.gif" width="5" height="9"></font></td>
<td width="48%" background="images/2bg.gif" height="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><img src="images/1nada.gif" width="5" height="9"></font></td>
</tr>
<tr>
<td width="52%" bgcolor="#E9E9E9">
<div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Agua
:</font></b></div>
</td>
<td width="48%" background="images/2bg.gif"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
<?
if ($row['Agua']==1){
echo "SI";
}
else{
echo "NO";
}?>
</font></td>
</tr>
</tbody>
</table>
<?
}
?>
</body>
</html>