我正试图从 services (表名)中获取'price'(列名)的值,以插入下面脚本中的var var。
任何帮助都将不胜感激。
<script type="text/javascript">
var amount = '100.00'; //need to insert amount here for each user before making payment
var currency = 'USD'; //
var discount = '0.00';//
服务(表格结构) 5列
s_id |名字|价格|折扣|删除
这是我在@Zanderwar评论之后尝试过的。
<?php
include '../with_session.php';
include '../db-connection.php';
session_start();
$id=$_SESSION['id'];
$sid="SELECT s_id WHERE id='$id'"; //to get s_id coloumn value
$resultsid=mysqli_query($con, $sid);
$rowid=mysqli_fetch_assoc($resultsid);
$qamount= "SELECT price FROM services WHERE s_id='.$resultsid'";// selecting price to insert into amount
$resultq= mysqli_query($con, $qamount);
$row_data = mysqli_fetch_assoc($resultq);
$row_data=$resultq;
?>
<html>
<head>
<link rel="stylesheet" href="https://www.paytabs.co/theme/express_checkout/css/express.css">
<script src="https://www.paytabs.co/theme/express_checkout/js/jquery-1.11.1.min.js"></script>
</head>
<body>
<!-- Button Code for PayTabs Express Checkout-->
<div class="checkout">
<script type="text/javascript">
var amount = '<?=$row_data['amount']?>'; //'100.00'; //
var currency = 'USD'; //3-character ISO Currency Code e.g: USD
var discount = '0.00';// Optional Field
var title = 'Test Express Checkout Transaction'; // Title of your transaction
</script> )
答案 0 :(得分:0)
您可以使用PHP回显值,显然需要一个活动的MySQL连接和一个名为$row_data
的结果集。
<script type="text/javascript">
var amount = '<?=$row_data['amount']?>'; //need to insert amount here for each user before making payment
var currency = '<?=$row_data['currency']?>'; //
var discount = '<?=$row_data['discount']?>';//
</script>
答案 1 :(得分:0)
试试这个
<?php
include '../with_session.php';
include '../db-connection.php';
session_start();
$id=$_SESSION['id'];
$sid="SELECT s_id WHERE id=".$id." "; //to get s_id coloumn value
$resultsid=mysqli_query($con, $sid);
while($rowid=mysqli_fetch_assoc($resultsid)) {
$re_id = $rowid['s_id'];
}
$qamount= "SELECT price FROM services WHERE s_id=".$re_id." ";// selecting price to insert into amount
$resultq= mysqli_query($con, $qamount);
while($row_data = mysqli_fetch_assoc($resultq)){
$price = $row_data['price'];
}
?>
<html>
<head>
<link rel="stylesheet" href="https://www.paytabs.co/theme/express_checkout/css/express.css">
<script src="https://www.paytabs.co/theme/express_checkout/js/jquery-1.11.1.min.js"></script>
</head>
<body>
<!-- Button Code for PayTabs Express Checkout-->
<div class="checkout">
<script type="text/javascript">
var amount = '<?=$price;?>'; //'100.00'; //
var currency = 'USD'; //3-character ISO Currency Code e.g: USD
var discount = '0.00';// Optional Field
var title = 'Test Express Checkout Transaction'; // Title of your transaction
</script>