2013-05-07 78 views
0

我在将数据从选定行显示到另一个div时遇到了问题。

含义我显示例如forename和lastname,当用户点击名称(作为链接)时,我想显示更多的数据从我选择的Id,我希望它显示在一个div下面的框。

在这里看到的网站:http://kristoff.it/onlinecoaching/

而且我的代码:

<div class="greenBox1"> 
     <h1>1 - VÆLG DIN ONLINE COACH</h1> 
      <div class="whiteBox1"> 
       <?php 
        $sql = "SELECT * FROM coach "; 

        $coachId = $row["coachId"]; 
        $fornavn = $row["fornavn"]; 
        $efternavn = $row["efternavn"]; 

        $result = mysql_query($sql);     
        while($row=mysql_fetch_assoc($result)) 
        { 

         echo '<table border="0" align="left" height="100">'; 
         echo '<tr>'; 
         echo '<td width="95" rowspan="2" align="center" valign="middle"><img src="' . $row['imgUrl'] . '" width="85" height="85" alt="' . $row['imgAlt'] . '"/>' . '</td>'; 
        ?> 
         <!-- here I'm trying to write the id of the selected name to the div box below -->        
        <? 
         echo '<td><a href="' . $coachId . '" target="whiteBox2"><h2>' . $row['fornavn'] . $row['efternavn'] . '</h2></a></td>'; 
         echo '</tr>'; 

         echo '<tr>'; 
         echo '<td valign="top" width="190"><p>' . $row['beskrivKort'] . '<br></p></td>'; 
         echo '</tr>'; 
         echo '</table>'; 
        }       
       ?>     
      </div> 
     </div> 

     <div class="greenBox2"> 
     <h1>2 - BOOK TID I COACHENS KALENDER</h1> 
      <div class="whiteBox2" id="whiteBox2"> 
      <!-- here would like the more data to show --> 
      </div> 
     </div> 

问候玛丽亚

+0

你在这段代码上面临的是什么pblm? – 2013-05-07 10:35:18

+0

但是仍然没有什么是写的 – 2013-05-07 10:57:11

回答

0

在您的网站,网址是空的。你需要把你的ID。

echo '<td><a href="URLOFYOURSITE?id=' . $coachId . '" target="whiteBox2"><h2>' . $row['fornavn'] . $row['efternavn'] . '</h2></a></td>'; 

使用该URL,您将发送该ID作为GET变量。 如果ID已设置,则必须请求您的数据。

<div class="whiteBox2" id="whiteBox2"> 
<?php 
if (isset($_GET['id'])) 
{ 
    $sql = "SELECT * FROM coach WHERE coachId=" . (int)$_GET['id']; 
    // Do your stuff... 
    echo "Hello"; 
} 
?> 
<!-- here would like the more data to show --> 
</div> 
+0

好吧,所以现在它的工作,谢谢你们,这是wonderfull,但我仍然不明白为什么它要在正确的框中打开数据,但我一个新的窗口?你能告诉我吗? – 2013-05-07 11:19:41

相关问题