在我的模态窗口中,我想获取数据行的ID字段,并在选择MYSQL中的变量中使用此ID。像这样:
$id= $row["id"];
$query = "SELECT * FROM storage WHERE id='$id'";
如果我这样做:
$id="<input type='text' id='id' name='id' />";
我可以显示此ID,但不能在我的模态中用作变量php。
试试这个...
$query = mysql_query("SELECT * FROM storage WHERE id={$id}");
$row = mysql_fetch_array($query);
echo '<input type="text" id="'.$row['id'].'" name="'.$row['id'].'" />';
嗨,如果您在MySQL咨询的同一页上使用此模式,您可以这样做:
<input type="text" id="id" name="id" value = value="<?php echo $id; ?>" />
希望能帮助到你
这是我的代码的一部分:
<!-- MODAL -->
<div class="modal fade" id="editor-modal">
<div class="modal-dialog" role="document">
<form class="modal-content form-horizontal" id="editor">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"></button>
<h4 class="modal-title" id="editor-title">Add</h4>
</div>
<div class="modal-body">
<input type="number" id="id" name="id" readonly/>
我的问题从这里开始。如何在select sql中使用Row id?
<?php // I get a field in array. ex (1,6,8,) which are the id of the selected places coming from another base.
$id = ???
$query = "SELECT * FROM storage_0 WHERE id='id'";
$result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_array($result))
{
$exp_string = $row["select_type"];
$exp_arr = explode(',', $exp_string);
for ($i = 0;$i < count($exp_arr);$i++)
{
$val['value_' . $i] = $exp_arr[$i];
}
}
?>
之后,我可以在我的模态中显示所选地点的列表。
<input type="hidden" id="id" name="id" class="hidden"/>
<div class="form-group">
<label for="type" class="col-sm-3 control-label">Types<span style="padding-left:5px;"><a title="Ajouter un Type" href="../type/editing.php?item=0"><i class="fa fa-edit fa-1x"></i></a></span></label>
<div class="col-sm-9">
<?PHP
$requete = $pdo->prepare('
SELECT id, type
FROM stock_type
WHERE del = 0
ORDER BY id ASC ;');
$requete->execute();
$datas = $requete->fetchAll();
foreach ($datas as $data)
{
if (in_array(intval($data->id) , $val))
{$selected = "checked";}else{$selected = "";}
?>
<span id="results"></span>
<label class="checkbox-inline">
<input type="checkbox" name="select_type[]" id="select_type" value="<?php echo $data->id; ?>" <?php echo $selected; ?>><?php echo $data->type; ?>
</label>
<?php } ?>
<!--...-->