我有以下代码,我想显示查询结果的名称。
function lead_delete(del_id)
{
<?php
$lead_name = mysql_query("select lead_name from business_lead where id=" .
$del_id) Or die(mysql_error());
while ($nt_lead_name = mysql_fetch_array($lead_name)) {
$crm_lead_name = $nt_lead_status['lead_name'];
}
?>
var name=<?php $crm_lead_name; ?>;
var confirmation;
var confirmation=confirm("You Really want to Detele Leader "+name );
}
</script>
如何打印从上面查询获得的名称...
答案 0 :(得分:0)
如果del_id
是php变量,那么它应该是$del_id
而不是del_id
var confirmation=confirm("You Really want to Detele Leader "+ <?php echo $del_id;?>);
当你将del_id
作为函数参数传递时,不需要使用php。您可以轻松获得如下变量
var confirmation=confirm("You Really want to Detele Leader " + del_id);
根据更新的问题: -
var name=<?php $crm_lead_name;?>;
应该是
var name= '<?php echo $crm_lead_name;?>';
而且你想要在click事件上传递del_id
lead_delete()函数,然后你必须在这里使用AJAX。
供您参考
http://blog.teamtreehouse.com/beginners-guide-to-ajax-development-with-php
答案 1 :(得分:0)
你不能在这个函数中使用<?php echo $del_id;?>
标记(因为你可以在调用函数时更改del_id),但是你可以在页面上创建del_id,如果你有$del_id
php值:
<script type="text/javascript">
var del_id = <?php echo $del_id;?>;
function lead_delete(del_id) {
var confirmation;
var confirmation=confirm("You Really want to Detele Leader " + del_id);
if(confirmation==true)
{
return true;
}
else
{
return false;
}
}
</script>