0

I am trying to assign a php echo value to an input generated from a jquery function. But so far no luck. It breaks the function and no results are displayed along with the input field. What is the proper way for this scenario to display php value inside the query function.

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 Answers 4

2

Try this

  <script language="javascript" type="text/javascript">
    var nextAutoIncrement = '<?php echo $next_increment;?>';
  </script>   
Sign up to request clarification or add additional context in comments.

2 Comments

would you happen to now if this is the proper way to assign value="4" for input field newSection.children(':nth-child(1)').children(':first').attr('id', 'auto_id_' + newNum).attr('name', 'auto_id_' + newNum).val(nextAutoIncrement)
I don't know what is your exact condition here but as per your comment I understand you want to assign value to input fields then yes you can achieve $('input selector class or id').val(inputValueVariable)
0

Try like this:

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

Comments

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

Comments

0

In JS code there is require to define the <script> tag:

$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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.