在jquery函数中回显PHP值

时间:2013-12-03 06:36:27

标签: php jquery

我正在尝试为从jquery函数生成的输入分配php echo值。但到目前为止还没有运气。它会中断该功能,并且不会在输入字段中显示任何结果。这个场景在查询函数中显示php值的正确方法是什么。

PHP

$tablename      = "table";
$next_increment     = 0;
//$qShowStatus        = "SHOW TABLE STATUS LIKE '$tablename'";
$qShowStatusResult  = $db_con->prepare("SHOW TABLE STATUS LIKE '$tablename'");
$qShowStatusResult->execute();
$results = $qShowStatusResult->fetchAll(\PDO::FETCH_ASSOC);
foreach($results as $value){
$next_increment = $value['Auto_increment'];
}


var nextAutoIncrement = '"'<?php echo $next_increment; ?>'"';

Jquery的

newSection.children(':nth-child(1)').children(':first').attr('id', 'auto_id_' + newNum).attr('name', 'auto_id_' + newNum).val(nextAutoIncrement).hide();   

4 个答案:

答案 0 :(得分:3)

试试这个

  <script language="javascript" type="text/javascript">
    var nextAutoIncrement = '<?php echo $next_increment;?>';
  </script>   

答案 1 :(得分:0)

试试这样:

<script language="javascript" type="text/javascript"
var nextAutoIncrement = <?php echo $next_increment; ?>;
</script>

答案 2 :(得分:0)

<script>
//if it is anumber
var nextAutoIncrement = <?php echo $next_increment; ?>;
// if ity is a string
var nextAutoIncrement = '<?php echo $next_increment;?>';
</script>

答案 3 :(得分:0)

在JS代码中,需要定义<script>标记:

$tablename      = "table";
$next_increment     = 0;

$qShowStatusResult  = $db_con->prepare("SHOW TABLE STATUS LIKE '$tablename'");
$qShowStatusResult->execute();
$results = $qShowStatusResult->fetchAll(\PDO::FETCH_ASSOC);
foreach($results as $value){
    $next_increment = $value['Auto_increment'];
}

<script type="text/javascript" >
var nextAutoIncrement = '<?php echo $next_increment; ?>';
</script>