在while循环中,我有医生姓名,专家和我的数据库付款。每位医生都有<input type="button">
名为&#34;做过&#34;。我希望当我按下按钮联系特定医生时,$row3['did']
的值将发送到我的contact.php
页面。但是我无法理解将它放在<input type="button">
中的哪个位置,以便我可以识别按下哪个按钮并将其值发送到contact.php
。
while($row3 = mysql_fetch_array($result3))
{
?>
<div class="col_1_of_4 span_1_of_4">
<div class="title-img">
<div class="title"><img src="images/Crystal_Clear_user.gif" alt=""></div>
<!--<div class="title-desc"><p>FACILITY 1</p></div>-->
<div class="clear"></div>
</div>
<h4 class=head>Doctor name: <?php echo $row3['dName'];?></h4>
<p>Specialist: <?php echo $row3['specialist'];?></p>
<p>Payment: <?php echo $row3['payment'];?></p>
<hr>
<div id='contact-form'>
<a href="#" class="btn btn-primary">more</a>
<!--<button id="findHelp" class="btn btn-primary"><a href="?did=<?php// echo $row3['did'];?>" >Find help</a></button>-->
<!--<a href="data/contact.php?did=<?php //echo $row3['did'];?>" ></a>-->
<!--<input type='button' name='contact' id='contact' value="Message" class='contact demo btn btn-primary'/>-->
<form method='post' action='contact.php'>
<input type='button' name='did' id='did' value="Message" class='contact demo btn btn-primary'/>
</form>
</div>
<!-- preload the images -->
<div style='display:none'>
<img src='images/loading.gif' alt='' />
</div>
</div>
<?php
}
?>
答案 0 :(得分:0)
无需添加表单。单击按钮时,只需发送带链接的id,并在联系.php页面上获取该ID ..
或使用如下
<script src="jquery.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$('.contact').click(function(){
var this_rel=$(this).attr('rel');
location.href="contact.php?id="+this_rel;
});
});
</script>
<input type='button' name='did' id='did' value="Message" class='contact demo btn btn-primary' rel="<?php echo $row3['did'];?>"/>
答案 1 :(得分:0)
尝试if(isset($_POST['button_name']) && $_POST['button_name'] === 'button_value')
答案 2 :(得分:0)
在表单中使用隐藏值,并在那里分配医生详细信息
<form method="post" action="contact.php">
<input type="hidden" name="thedoctor" value="<?php echo $row3['did'];?>"/>
<input type="button" name="did" id="did" value="Message" class="contact demo btn btn-primary"/>
</form>
然后按$button_clicked = $_POST['thedoctor']
答案 3 :(得分:0)
这将是您的PHP代码
<?php
while($row3 = mysql_fetch_array($result3))
{
?>
<div class="col_1_of_4 span_1_of_4">
<div class="title-img">
<div class="title"><img src="images/Crystal_Clear_user.gif" alt=""></div>
<!--<div class="title-desc"><p>FACILITY 1</p></div>-->
<div class="clear"></div>
</div>
<h4 class=head>Doctor name: <?php echo $row3['dName'];?></h4>
<p>Specialist: <?php echo $row3['specialist'];?></p>
<p>Payment: <?php echo $row3['payment'];?></p>
<hr>
<div id='contact-form'>
<a href="#" class="btn btn-primary">more</a>
<input type='button' name='did' id='did' value="Message" class='contact demo btn btn-primary' rel="<?php echo $row3['did'];?>"/>
</div>
<!-- preload the images -->
<div style='display:none'>
<img src='images/loading.gif' alt='' />
</div>
</div>
<?php
}
?>
以上,放了一些jquery代码
<script src="jquery.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$('.contact').click(function(){
var this_rel=$(this).attr('rel');
location.href="contact.php?id="+this_rel;
});
});
</script>
别忘了写数据库的查询,因为那不是你的例子,这就是我没有提到的原因。还要将jquery.js添加到适当的位置,以便运行jquery代码。请这个技巧让我知道..
答案 4 :(得分:0)
只需使用buttons
:
<form method="POST">
<button type="submit" name="btn_action_1" value="abc">Message</button>
<button type="submit" name="btn_action_1" value="def">Message</button>
<button type="submit" name="btn_action_1" value="ghi">Message</button>
<button type="submit" name="btn_action_1" value="jkl">Message</button>
<button type="submit" name="btn_action_2" value="123">Message</button>
<button type="submit" name="btn_action_3" value="456">Message</button>
</form>
<?php
if(isset($_POST['btn_action_1'])) {
echo 'btn_action_1 was pressed with value: '. $_POST['btn_action_1'];
}
if(isset($_POST['btn_action_2'])) {
echo 'btn_action_2 was pressed with value: '. $_POST['btn_action_2'];
}