繁体   English   中英

Drupal SQL表如何在每行上插入编辑按钮

[英]Drupal SQL table how to insert edit button on each row

我在Drupal中有一个带有以下代码的表:

$db = mysql_connect("localhost", "root", "moocow");
mysql_select_db("vedb", $db); 
$result = mysql_query("SELECT NodeID,NodeDesc,NodeZone,Fusion,DSLID FROM      `nodeidtable` WHERE DSLID != '' AND `NodeZone` = 'CLOSED' ORDER BY NodeID ASC"); 
$num_rows = mysql_num_rows($result);
echo "<table>"; 
echo "<tr>"; 
echo "<th>CLOSED SITES</th>"; 
echo "<th></th>"; 
echo "<th></th>"; 
echo "<th></th>"; 
echo "<th></th>"; 
echo "</tr>"; 
echo "<tr>"; 
echo "<th>Node ID</th>"; 
echo "<th>Node Address</th>"; 
echo "<th>Node Zone</th>"; 
echo "<th>Fusion Status</th>"; 
echo "<th>Service Number</th>"; 
echo "</tr>"; 
//display the data 
while ($rows = mysql_fetch_array($result,MYSQL_ASSOC)) 
{ 
  echo "<tr>"; 
  foreach ($rows as $data) 
  { 
    echo "<td align='center'>". $data . "</td>"; 
  } 
} 

echo "<br>";
echo "<tr>"; 


echo "</table>"; 

mysql_free_result($result);
mysql_close($db);
?>

现在,我可以更改它以使td包含各个列,但是我真的想在右侧添加一个小的编辑按钮,这将允许我编辑该特定行字段。

有任何想法吗?

用以下代码替换while循环:

 while ($rows = mysql_fetch_array($result,MYSQL_ASSOC)) 
 { 
    echo "<tr>"; 
    foreach ($rows as $data) 
    { 
       echo "<td align='center'>". $data . "</td>"; 
    }


   //create link for current node edit
    echo "<td align='center'>". l(t('Edit this node'), 'node/' . $row['NodeId'] . '/edit') ."</td>";
    echo "</tr>"; 
 } 

删除echo "<br>"; and echo "<tr>"; echo "<br>"; and echo "<tr>"; 下面到while循环。 这将为您解决问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM