从php嵌入变量
我正在尝试将php脚本中的数据库值关联/嵌入到我的api URL中 但我不知道如何正确使用它,我不熟悉php 它需要嵌入来自DB的变量,以便像这样访问API值 api/rfq/1(示例) 我已经试过了 php代码:从php嵌入变量,php,jquery,mysql,Php,Jquery,Mysql,我正在尝试将php脚本中的数据库值关联/嵌入到我的api URL中 但我不知道如何正确使用它,我不熟悉php 它需要嵌入来自DB的变量,以便像这样访问API值 api/rfq/1(示例) 我已经试过了 php代码: <?php require_once('connection.php'); session_start(); if(!$con){ die('Please Check Your Connection'.mysqli_error()); }else{ $qu
<?php
require_once('connection.php');
session_start();
if(!$con){
die('Please Check Your Connection'.mysqli_error());
}else{
$query="select BusinessID from business where username='".$_SESSION['User']."'";
$result=mysqli_query($con,$query);
while($row =mysqli_fetch_array($result)){
$results[]=implode($row['BusinessID']);
}
echo json_encode($results);
// echo 'Works ASF '+$hey;
}
?>
$(function() {
$.getJSON('getID.php', function(data) {
$.each(data, function() {
alert(data.column);
})
})
var $hello = $('#hello');
$.ajax({
type: 'GET',
dataType: "json",
url: 'http://slimapp/api/rfq/"'+$_SESSION['User']+'"',
success: function(hello){
$.each(hello, function(i,order){
$hello.append('<div class="panel panel-default"><div class="panel-thumbnail"></div><div class="panel-body"><p class="lead"><b><img src="assets/img/Profile.png" height="28px" width="28px">'+order.Title+'<a href="#postModal" class="pull-right" role="button" data-toggle="modal"><i class="glyphicon glyphicon-plus"></i>Make Bid</a></b></p><p><img src="assets/img/RFQ.png" height="28px" width="28px">'+order.Description+'</p><p><img src="assets/img/Clock.png" height="28px" width="28px">'+order.Date+'</p><hr/><p><img src="assets/img/email.png" height="28px" width="28px"><a href="https://mail.google.com/mail/?view=cm&fs=1&to=someone@example.com&su=SUBJECT&body=BODY&bcc=someone.else@example.com">'+order.email+'</a></p><p><img src="assets/img/Phone.png" height="28px" width="28px"><a href="">'+order.cellphone+'</a><p><textarea class="form-control" placeholder="Comment"></textarea><br/><li id="btn1"></li><button class="btn btn-success pull-left" type="button" style="border-radius:12px">Comment</button></p></div></div>');
})
}
})
});
Jquery文件应如下所示:
function apiCall(user) {
var url = 'http://slimapp/api/rfq/'+ user +''; // This var is creating the right URL, using the parameter USER of the function
$.ajax({
type: 'GET',
dataType: "json",
url: url, // Calling the new right URL
success: function(hello){
// Handle your success
}
})
};
<?php
$results = '1';
?>
<script>
apiCall(<?php echo $results ?>); // Passing the value 1 as a parameter for the function
</script>
在这里,您正在创建一个新函数,该函数接收要在URL中传递的参数User
您的PHP文件应如下所示:
function apiCall(user) {
var url = 'http://slimapp/api/rfq/'+ user +''; // This var is creating the right URL, using the parameter USER of the function
$.ajax({
type: 'GET',
dataType: "json",
url: url, // Calling the new right URL
success: function(hello){
// Handle your success
}
})
};
<?php
$results = '1';
?>
<script>
apiCall(<?php echo $results ?>); // Passing the value 1 as a parameter for the function
</script>
apiCall();//将值1作为函数的参数传递
在这里,您调用函数apiCall并将变量$results的值作为参数传递。在这个函数上使用jQuery可能会复制im,并且我不熟悉它的语法。您只需要添加php标记,如:url:'