我可以把PHP链接到$ query吗?

时间:2017-12-30 08:13:17

标签: php html mysql

所以这是我的代码

mysql_select_db($database_Myconnec, $Myconnec);    
$query_service = "SELECT service.Service_id,            
IF(physical.Service_id IS NULL, ('Add'), ('Edit')) as physical  
FROM service LEFT JOIN physical ON (service.Service_id = physical.Service_id )";  
$service = mysql_query($query_service, $Myconnec) or die(mysql_error());  
$row_service = mysql_fetch_assoc($service);  
$totalRows_service = mysql_num_rows($service);



    <table border="1" class="floatedTable">
  <tr>
    <td><div align="center">Service ID</td>
    <td><div align="center">Physical Check</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><div align="center"><?php echo $row_service['Service_id']; ?></td>
      <td><div align="center"><?php echo $row_service['physical']; ?></td>  
    </tr>
    <?php } while ($row_service = mysql_fetch_assoc($service)); ?>
</table>

我想要的是“添加&#39;和&#39;编辑&#39;如果在表格中显示,我将如何显示为可点击的php链接?

1 个答案:

答案 0 :(得分:3)

如果我理解的话,你可以做一些类似于此的事情

<table border="1" class="floatedTable">
  <tr>
    <td><div align="center">Service ID</td>
    <td><div align="center">Physical Check</td>
  </tr>
  <?php 

  do {

    $id=$row_service['Service_id'];
    $phys=$row_service['physical'];
    $action=$phys=='Add' ? 'add.php' : 'edit.php'; #assumed script names correspond to text

  ?>
    <tr>
      <td><div align="center"><?php echo $id; ?></td>
      <td><div align="center"><?php echo "<a href='{$action}?id={$id}' title='$phys'>$phys</a>";?></td>  
    </tr>
    <?php } while ($row_service = mysql_fetch_assoc($service)); ?>
</table>
# view.php
# --------

<table border="1" class="floatedTable">
  <tr>
    <td><div align="center">Service ID</td>
    <td><div align="center">Physical Check</td>
  </tr>
  <?php 

  do {

    $id=$row_service['Service_id'];
    $phys=$row_service['physical'];
    $action=$phys=='Add' ? 'add.php' : 'edit.php'; #assumed script names correspond to text

  ?>
    <tr>
      <td><div align="center"><?php echo $id; ?></td>
      <td><div align="center"><?php echo "<a href='{$action}?id={$id}' title='$phys'>$phys</a>";?></td>  
    </tr>
    <?php } while ($row_service = mysql_fetch_assoc($service)); ?>
</table>



# add.php
# -------

$id = isset( $_GET['id'] ) ? $_GET['id'] : false;
if( $id ){

    /* 
        generate form to add record
        use $id somewhere?
    */

}




# edit.php
# --------
$id = isset( $_GET['id'] ) ? $_GET['id'] : false;
if( $id ){

    /* 
        do stuff - generate form to edit content etc 
        use $id to lookup data
    */

}

参考您关于删除特定值超链接的最新评论 - 或许尝试这样?

  do {

    $id=$row_service['Service_id'];
    $phys=$row_service['physical'];
    $action=$phys=='Add' ? 'add.php' : 'edit.php'; #assumed script names correspond to text

    if( strtolower( $phys )=='wait' )$content=$phys;
    else $content="<a href='{$action}?id={$id}' title='$phys'>$phys</a>";
  ?>
    <tr>
      <td><div align="center"><?php echo $id; ?></td>
      <td><div align="center"><?php echo $content; ?></td>  
    </tr>
    <?php } while ($row_service = mysql_fetch_assoc($service)); ?>
</table>