Problem med udtræk fra 3 tabeller i database
Hej eksperter,Jeg er newbie indenfor PHP, og har derfor brug for lidt hjælp til et lille script jeg har gang i.
Nestående er mit forsøg på at lave et lille script som henter noget data ud fra 3 forskellige tabeller i en database og derefter udskriver den. Desværre får jeg fejl med mit script, men er også helt sikker på at det kan gøres på en pænere måde.
<?php
mysql_connect("localhost", "********", "********") or die(mysql_error()); mysql_select_db("database") or die(mysql_error());
$data = mysql_query("SELECT * FROM tabel1 where id='{$_GET['id']}'") or die(mysql_error());
$dara2 = mysql_fetch_assoc($data);
$data4 = mysql_query("SELECT * FROM tabel2 where id='" . $data2['plans_id'] . "'") or die(mysql_error());
$dara3 = mysql_fetch_assoc($data4);
$query="SELECT * FROM tabel1 where id='{$_GET['id']}'";
$result=mysql_query($query);
$query2="SELECT * FROM tabel2 where id='" . $data2['plans_id'] . "'";
$result2=mysql_query($query2);
$query3="SELECT * FROM mtabel3 where id='" . $data3['network_id'] . "'";
$result3=mysql_query($query3);
$num=mysql_numrows($result);
mysql_close();
?>
<table class="data" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="hd" style="width: 130px;"></td>
<td class="hd" style="width: auto;"></td>
<td class="hd" style="width: 145px;"></td>
</tr>
<?php
$i=0;
while ($i < $num) {
$pris=mysql_result($result,$i,"pris");
$link=mysql_result($result,$i,"link");
$navn=mysql_result($result2,$i,"name");
$datafelt1=mysql_result($result2,$i,"datafelt1");
$datafelt2=mysql_result($result2,$i,"datafelt2");
$datafelt3=mysql_result($result2,$i,"datafelt3");
$datafelt4=mysql_result($result2,$i,"datafelt4");
$datafelt5=mysql_result($result2,$i,"datafelt5");
$datafelt6=mysql_result($result2,$i,"datafelt6");
$datafelt7=mysql_result($result2,$i,"datafelt7");
$datafelt8=mysql_result($result2,$i,"datafelt8");
$datafelt9=mysql_result($result2,$i,"datafelt9");
$logo=mysql_result($result3,$i,"logo");
$network=mysql_result($result3,$i,"network");
?>
<tr onclick="java script:window.open('<? echo "$link"; ?>');" class="trhand" bgcolor="#f1f1f1" onmouseover="this.bgColor = '#e3f4f8';" onmouseout ="this.bgColor = '#f1f1f1';return true;">
<td class="dataclass">
<img src="img/<? echo "$logo"; ?>" alt="<? echo "$network"; ?>" border="1" />
</td>
<td class="dataclass">
<div class="dataover"><? echo "$navn"; ?></div>
<div class="dataclass2"><b>Datafelt1:</b> <? echo "$datafelt1"; ?><br /><b>Datafelt2:</b> <? echo "$datafelt2"; ?><br /><b>Datafelt3:</b> <? echo "$datafelt3"; ?></div>
<div class="dataclass2"><b>Datafelt4:</b> <? echo "$datafelt4"; ?><br /><b>Datafelt5:</b> <? echo "$datafelt5"; ?><br /><b>Datafelt6:</b> <? echo "$datafelt6"; ?></div>
<div class="dataclass2"><b>Datafelt7:</b> <? echo "$datafelt7"; ?><br /><b>Datafelt8:</b> <? echo "$datafelt8"; ?><br /><b>Datafelt9:</b> <? echo "$datafelt9"; ?></div>
</td>
<td class="dataclass_koeb rh">
<div class="pris">Pris DKK <? echo "$pris"; ?>,-</div><img src="img/koebnu.png" alt="Køb nu!" /><br />
</td>
</tr>
<?php
++$i;
}
echo "</table>";
?>