2011-07-06 52 views
0

我需要你的幫助。 我有表使用PHP while循環 我需要幫助如何從表中選定的行中獲取id,然後將其發送到另一頁。我需要這樣做,因爲表不查看細節,所以我需要該ID來查看完整表格的詳細信息或查詢。使用PHP發送和獲取ID循環時使用PHP

以下是我的代碼

<?php 

include('config.php'); 
session_start(); 

$table = "select * from rekuest"; 
$select = mysql_query($table); 

$user = $_SESSION['username']; 
?> 
<head> 
     <title>Home</title> 
     <link href="css/960.css" rel="stylesheet" media="screen" /> 
     <link href="css/defaultTheme.css" rel="stylesheet" media="screen" /> 
     <link href="css/myTheme.css" rel="stylesheet" media="screen" /> 
     <script src="js/jquery-1.6.1.js"></script> 

    <script src="js/jquery.fixedheadertable.min.js"></script> 
    <script src="js/demo.js"></script> 

    <style type="text/css" media="screen"> 
     #tombol { 
      display: block; 
      width: 90px; 
      height: 30px; 
      background: url(img/tombol_normal2.png) no-repeat top; 
     } 
     #tombol:active { 
      background: url(img/tombol_pressed.png) no-repeat bottom; 
     } 
    </style> 

</head> 
<body> 
<h1 align="center">List All Of Request</h1> 
<h2 align="center">Welcome, <?php echo $_SESSION['username']; ?></h2> 

<form> 
    <input type="button" name="new" value="New Request" align="right" 
    onClick="window.location='form.php'"/> 
    <input type="button" onClick="window.location = 'logout.php?exit=yes'" class="myButton" value="Logout"/> 

</form> 
<div id="divider"> 
</div> 

<table width="900" align="center" cellpadding="0" cellspacing="0" class="myTable04"> 
    <thead> 
     <tr> 
      <th>No Reff</th> 
      <th>Subjek Request</th> 
      <th width="20px">Permintaan</th> 
      <th>Waktu</th> 
      <th>Jenis Request</th> 
      <th>Customer</th> 
      <th>Sifat Requirement</th> 
      <th>Pelaksana</th> 
      <th>Status</th> 
      <th>Respon</th> 
      <th>Rekomen</th> 
      <th>Nama File</th> 
      <th>Attachment</th> 
      <th>Detail</th> 
     </tr> 
    </thead> 
    <tbody> 
    <?php while($row = mysql_fetch_array($select)) { ?> 
     <tr> 
      <td><?php echo $row['id_rekuest']; ?></td> 
      <td><?php echo $row['subjek']; ?></td> 
      <td><?php echo $row['permintaan']; ?></td> 
      <td><?php echo $row['waktu']; ?></td> 
      <td><?php echo $row['jenis']; ?></td> 
      <td><?php echo $row['customer']; ?></td> 
      <td><?php echo $row['sifat']; ?></td> 
      <td><?php echo $row['pelaksana']; ?></td> 
      <td><?php echo $row['status']; ?></td> 
      <td><?php ?></td> 
      <td><?php ?></td> 
      <td><?php ?></td> 
      <td><?php ?></td> 
      <td><a id="tombol" style="cursor:pointer" onClick="window.location='detail.php'"></a></td> 
     </tr> 

    <?php } ?> 
    </tbody> 
</table> 

回答

0

我不是100%知道你在問什麼,但我想你想要的是將id傳遞給詳細信息頁面。你可以用下面通過一個GET做到這一點:

<td> 
    <a id="tombol" style="cursor:pointer" href="detail.php?id=<?php echo $row['id_rekuest']; ?>"></a> 
</td> 

然後用$ _GET [「身份證」](消毒,拜託了!)查詢基於該ID

+0

感謝alex,是的,您是正確的答案,並感謝很多修復我的帖子。我在這個論壇和PHP非常nubie –

2

而不是

<td><a id="tombol" style="cursor:pointer" onClick="window.location='detail.php'"></a></td> 

我會把

<td><a id="tombol" href="detail.php?id=<?php echo $row['id_rekuest']; ?>">Details</a></td> 

然後,在detail.php你可以得到的ID從$_GET['id']

+0

只是一個預留任何數據庫,而不是'<?php echo $ var; ?''你也可以使用''。 –

+0

感謝您的幫助,非常感謝,作爲nubie在php編程中對我非常重要 –