Php 结果是在ajax成功中实现了连接
这是我的ajax调用代码…我在body onload上调用这个函数Php 结果是在ajax成功中实现了连接,php,ajax,codeigniter,Php,Ajax,Codeigniter,这是我的ajax调用代码…我在body onload上调用这个函数 function get_booking_id() { var baseurl = "<?php echo base_url().'index.php/controller_bookplot2/getbookingid'; ?>"; $.ajax({ url: baseurl, datatype:"html", success: function
function get_booking_id() {
var baseurl = "<?php echo base_url().'index.php/controller_bookplot2/getbookingid'; ?>";
$.ajax({
url: baseurl,
datatype:"html",
success: function(html) {
alert('booking'+html);
$("#booking_id").val(html);
}
});
}
所以在警报中,当数据库中没有值时,它显示1,但下次它显示12而不是2。所以我认为这是连接结果。我只想将2作为警报,而不是12。我做错了什么?请删除$x=$row->bookingID的echo;如果你不需要回应 更新控制器功能代码:
function getbookingid(){
$sql="select IFNULL(max(booking_id),0) as bookingID from booking";
$query=$this->db->query($sql);
if($query->num_rows() > 0){
foreach($query->result() as $row){
$x=$row->bookingID;
echo $x+1;
}
}
}
当没有值时,您将获得echo$x+1;,(1) 当您返回一个值时,您将得到echo$x=$row->bookingID;(值为1)和echo$x+1;(值为2,值为1加1的$x为2),因此在脚本中得到12 您可以尝试删除其中一个回声:
function getbookingid() {
$sql="select IFNULL(max(booking_id),0) as bookingID from booking";
$query=$this->db->query($sql);
if($query->num_rows() > 0) {
foreach($query->result() as $row) {
$x = $row->bookingID;
echo $x;
}
}
}
我不知道..是对还是错?为什么
alert('booking'+html)代码>而不仅仅是警报(html)代码>?只需知道它与预订相关。因为我使用了相同的函数来获取付款id。当DB中没有值时,如何获得1
????发布查询结果选择IFNULL(max(booking_id),0)作为bookingID from booking
。您的PHP/DB代码返回了两个内容。因此,如果第一个echo上的$x=1,那么按照您编写的逻辑,$x=2。因此js将两个echo都捕获为输出&添加到警报字符串中
function getbookingid() {
$sql="select IFNULL(max(booking_id),0) as bookingID from booking";
$query=$this->db->query($sql);
if($query->num_rows() > 0) {
foreach($query->result() as $row) {
$x = $row->bookingID;
echo $x;
}
}
}