Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获得';id';来自数据库内部的href_Php_Database_Xampp - Fatal编程技术网

Php 如何获得';id';来自数据库内部的href

Php 如何获得';id';来自数据库内部的href,php,database,xampp,Php,Database,Xampp,我有一个表名问题。在该表中,我有一个列名“dateclose”。每次我添加数据时,它都会在该列中自动创建一个数据。代码如下: $sam = '<a href="sams.php" id='.$_POST['incidentnum'].'>Close Issue</a>'; 要获取id,必须将其作为查询参数传递 您可以这样做: $sam = '<a href="sams.php?id='.$_POST['incidentnum'].'">Close Issu

我有一个表名问题。在该表中,我有一个列名“dateclose”。每次我添加数据时,它都会在该列中自动创建一个数据。代码如下:

 $sam = '<a href="sams.php" id='.$_POST['incidentnum'].'>Close Issue</a>';

要获取
id
,必须将其作为查询参数传递

您可以这样做:

$sam = '<a href="sams.php?id='.$_POST['incidentnum'].'">Close Issue</a>';

希望这有帮助。并确保处理未传递id或传递错误id的情况。

1st:在数据库中插入html代码不是一个好做法

2nd:只需像下面这样传递查询参数

<a href="sams.php?id=<?php echo $_POST['incidentnum'] ?>">Close Issue</a>
$incidentnum= $_GET['id'];
4th:更新查询

 "UPDATE issue SET dateclose =CURDATE()  WHERE incidentnum='$incidentnum'";
5th:更改html表格呈现部分。在行创建中,将
dateclose
列设置为
null

$html_table = '<table align="center" border="1" cellspacing="0" cellpadding="5" width="800" word-wrap="break-word" display="inline-block"> 
              <tr><th>Incident #</th><th>Issue</th>th>Date Closed</th></tr>'; 
foreach($result as $row){ 

    $html_table .= '<tr>
                        <td>' .$row["incidentnum"]. '</a></td>
                        <td>' .$row["issue"]. '</td> 
                        <td>';
   if(is_null($row["dateclose"])){  

      $html_table.="<a href='sams.php?id=<?php echo $row[\"incidentnum \"] ?>'>Close Issue</a>";

    }else{

       $html_table.=$row["dateclose"]; 
  }
                  $html_table. '</td>

                    </tr>';

     }
$html\u table=>
事件#发布>关闭日期';
foreach($结果为$行){
$html_表格='
“.$row[“incidentnum”]”
“.$row[“发行”]”
';
如果(为空($row[“dateclose”]){
$html_表格=“”;
}否则{
$html_table.=$row[“dateclose”];
}
$html_表。”
';
}

5th:尝试使用
Prepared语句或pdo
来避免
sql注入

实际上您的问题并不太清楚。 但我认为您的要求是每当用户单击


因此,只要在数据库显示屏上插入CURDATE(),就可以了。

从数据库检索行后,可以使用正则表达式获取id的内容

例:


不清楚您想要什么。在数据库中插入html代码不是一个好的做法。我想做的是,如果我单击“关闭问题”链接,单元格将更改为当前日期,这就是我使用html代码的原因。是的,这实际上是我想做的,这就是我使用html代码的原因。因此,您必须以以下方式更新代码:然后在sams.php中您已写入更新查询以保存关闭日期。这很简单。这是我在sams.php$sql=“UPDATE issue SET dateclose='$dateclose'中的查询,其中incidentnum='$incidentnum';sams.php中的正确查询如下:$sql=“更新问题集dateclose=CURDATE(),其中incidentnum=”$incidentnum';我只想做的是,如果我单击“关闭问题”链接,单元格将更改为当前日期,这就是为什么我在表中使用html代码@JYoThIyes如何呈现html表的代码@user8230483$html(u table='Incident#Issueth>dateclosed';foreach($result as$row){$html_table.='.$row[“incidentnum”].'.$row[“issue”].'.$row[“dateclose”]“;看看我的最新答案。特别是最后5点td@user8230483我想做的是,如果我单击“关闭问题”链接,单元格将更改为当前日期,这就是我使用html的原因code@user8230483我们从来没有说过不要使用HTML。你必须使用它在浏览器中呈现链接,但将其存储在DB中不是一个好方法想法。除此之外,你现在可以使用id并可以更新截止日期。这是我知道的唯一截止日期的方法
$incidentnum= $_GET['id'];
 "UPDATE issue SET dateclose =CURDATE()  WHERE incidentnum='$incidentnum'";
$html_table = '<table align="center" border="1" cellspacing="0" cellpadding="5" width="800" word-wrap="break-word" display="inline-block"> 
              <tr><th>Incident #</th><th>Issue</th>th>Date Closed</th></tr>'; 
foreach($result as $row){ 

    $html_table .= '<tr>
                        <td>' .$row["incidentnum"]. '</a></td>
                        <td>' .$row["issue"]. '</td> 
                        <td>';
   if(is_null($row["dateclose"])){  

      $html_table.="<a href='sams.php?id=<?php echo $row[\"incidentnum \"] ?>'>Close Issue</a>";

    }else{

       $html_table.=$row["dateclose"]; 
  }
                  $html_table. '</td>

                    </tr>';

     }
$sam = '<a href="sams.php" id=213>Close Issue</a>';

preg_match('#(?<=id=).*?(?=>)#', $sam, $match);

var_dump($match);
array(1) { 
   [0] => string(3) "213" 
}