我知道这可能已经回答,但我找不到与此有关的任何内容。所以这就是我正在努力的事情: -
我有两个值,我在复选框中传递: -
<input name='class[]' type='checkbox' class='checkbox' value='".$x_value['type1'].":".$x_value['type2']."'>
在跑步时: -
<input name="class[]" type="checkbox" class="checkbox" value="2681:14175">
所以我想要的是如何在URL中传递由“:”分隔的这些值。
这样的事情: -
http://domainname.com/approve.php?type1=2681&type2=14175
目的: -
实际上,我从使用CURL的API响应中获取这些值并生成多个复选框。每个复选框包含两个以“:”分隔的值。
现在我想在不同的文件中运行一个单独的API,它将从URL获取值。
更新:以下是完整的代码: -
<?php
foreach($apiResponse['response']['data'] as $x =>$x_value) {
foreach($x_value as $x => $x_value) {
echo "<tr>";
echo "<td style='width:10px;'><input name='class[]' type='checkbox' class='checkbox' value='".$x_value['type1'].":".$x_value['type2']."'></td>";
echo "<td style='width:50px;'>".$x_value['type1']."</td>";
echo "<td>".$x_value['type2']."</td>";
echo "<td>".$x_value['approval_status']."</td>";
echo "<td> <a href='approve.php?type1=".$x_value['type1_value']."&type2_value=".$x_value['type2_value']."'> Approve </a> </td>";
echo "<td><a href='reject.php?type1_value=".$x_value['type1_value']."&type2_value=".$x_value['type2_value']."'> Reject </a></td>";
echo "</tr>";
}
}
?>
更新第2号: -
获取记录的API: -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pending apps</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css">
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/plug-ins/9dcbecd42ad/integration/bootstrap/3/dataTables.bootstrap.css">
<script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" language="javascript" src="//cdn.datatables.net/1.10.3/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="../../hasoffers/dataTables.bootstrap.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#example').DataTable( {
stateSave: true
} );
} ); </script>
<!-- Bootstrap
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">-->
<!-- Optional theme
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">-->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
/*.filterable {
margin-top: 15px;
}
.filterable .panel-heading .pull-right {
margin-top: -20px;
}
.filterable .filters input[disabled] {
background-color: transparent;
border: none;
cursor: auto;
box-shadow: none;
padding: 0;
height: auto;
}
.filterable .filters input[disabled]::-webkit-input-placeholder {
color: #333;
}
.filterable .filters input[disabled]::-moz-placeholder {
color: #333;
}
.filterable .filters input[disabled]:-ms-input-placeholder {
color: #333;
}
*/
</style>
</head>
<body>
<div class="container">
<?php
error_reporting(0);
ini_set('memory_limit', '-1');
// Specify API URL
define('HASOFFERS_API_URL', 'http://api.hasoffers.com/Apiv3/json');
// Specify method arguments
$args = array(
'NetworkId' => 'abc',
'Target' => 'Offer',
'Method' => 'findAllPendingAffiliateApprovals',
'NetworkToken' => 'asdasdasd',
'filters' => array(
'approval_status' => 'pending'
),
'fields' => array(
'affiliate_id',
'offer_id',
'approval_status',
'id'
)
//'limit' => '100',
);
// Initialize cURL
$curlHandle = curl_init();
// Configure cURL request
curl_setopt($curlHandle, CURLOPT_URL, HASOFFERS_API_URL . '?' . http_build_query($args));
// Make sure we can access the response when we execute the call
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
// Execute the API call
$jsonEncodedApiResponse = curl_exec($curlHandle);
// Ensure HTTP call was successful
if($jsonEncodedApiResponse === false) {
throw new \RuntimeException(
'API call failed with cURL error: ' . curl_error($curlHandle)
);
}
// Clean up the resource now that we're done with cURL
curl_close($curlHandle);
// Decode the response from a JSON string to a PHP associative array
$apiResponse = json_decode($jsonEncodedApiResponse, true);
// Make sure we got back a well-formed JSON string and that there were no
// errors when decoding it
$jsonErrorCode = json_last_error();
if($jsonErrorCode !== JSON_ERROR_NONE) {
throw new \RuntimeException(
'API response not well-formed (json error code: ' . $jsonErrorCode . ')'
);
}
// Print out the response details
if($apiResponse['response']['status'] === 1) {
// No errors encountered
// echo 'API call successful';
// echo PHP_EOL;
// echo 'Response Data: ' . print_r($apiResponse['response']['data'], true);
// echo PHP_EOL;
}
else {
// An error occurred
echo 'API call failed (' . $apiResponse['response']['errorMessage'] . ')';
echo PHP_EOL;
echo 'Errors: ' . print_r($apiResponse['response']['errors'], true);
echo PHP_EOL;
}
?>
</div>
<div class="container">
<h3>Affiliates Details</h3>
<p><span>Total Records:-<?php print_r($apiResponse['response']['data']['count']); ?></span></p>
<hr>
<script type="application/javascript">
function toggleChecked(status) {
$(".checkbox").each( function() {
$(this).attr("checked",status);
})
}
</script>
<table class="table table-striped table-bordered" id="example">
<thead>
<tr class="filters">
<th><input type="checkbox" class="checkall" onclick="toggleChecked(this.checked)"></th>
<th>Affiliate Id</th>
<!-- <th>Affiliate Name</th> -->
<th>Offer ID</th>
<!-- <th>Offer Name</th> -->
<th>Status</th>
<th>Action</th>
<th>Action</th>
<!-- <th>Adv info</th> -->
<!-- <th>Aff Info</th> -->
<!-- <th>Date</th> -->
</tr>
</thead>
<tbody>
<?php
foreach($apiResponse['response']['data'] as $x =>$x_value) {
// echo "Affiliate ID" . $x . ", Value=" ;
//print_r($x_value);
foreach($x_value as $x => $x_value) {
// $sss = $x_value['affiliate_id'];
echo "<tr>";
echo "<td style='width:10px;'><form><input name='v1' type='checkbox' class='checkbox' value='".$x_value['offer_id']."|".$x_value['affiliate_id']."'></form></td>";
echo "<td style='width:50px;'>".$x_value['affiliate_id']."</td>";
// echo "<td>".$x_value['company']."</td>";
echo "<td>".$x_value['offer_id']."</td>";
// echo "<td>".$x_value['name']."</td>";
echo "<td>".$x_value['approval_status']."</td>";
echo "<td> <a href='approve.php?offerid=".$x_value['offer_id']."&affid=".$x_value['affiliate_id']."'> Approve </a> </td>";
echo "<td><a href='reject.php?offerid=".$x_value['offer_id']."&affid=".$x_value['affiliate_id']."'> Reject </a></td>";
// echo "<td>".$x_value['advertiser_info']."</td>";
// echo "<td>".$x_value['affiliate_info1']."</td>";
// echo "<td>".$x_value['datetime']."</td>";
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
<?php
list($value1,$value2) = explode('|', $_GET['v1']);
echo "value1 = ".$value1.", value2 = ".$value2."<br>";
?>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>-->
<!-- Include all compiled plugins (below), or include individual files as needed
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>-->
</body>
</html>
用于更改多个记录状态的API: -
第二个URL将如下所示: -
http://www.domain.com/approve.php?offerid=123&affid=456
将从复选框值
传递哪个商品ID和商品<?php
// Specify API URL
define('HASOFFERS_API_URL', 'http://api.hasoffers.com/Apiv3/json');
// Specify method arguments
$args = array(
'NetworkId' => 'anc',
'Target' => 'Offer',
'Method' => 'setAffiliateApproval',
'NetworkToken' => 'asdasdasdasd',
'id' => '' . htmlspecialchars($_GET["offerid"]) .'',
'affiliate_id' => '' . htmlspecialchars($_GET["affid"]) .'',
'status' => 'approved'
);
// Initialize cURL
$curlHandle = curl_init();
// Configure cURL request
curl_setopt($curlHandle, CURLOPT_URL, HASOFFERS_API_URL);
// Configure POST
curl_setopt($curlHandle, CURLOPT_POST, 1);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, http_build_query($args));
// Make sure we can access the response when we execute the call
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
// Execute the API call
$jsonEncodedApiResponse = curl_exec($curlHandle);
// Ensure HTTP call was successful
if($jsonEncodedApiResponse === false) {
throw new \RuntimeException(
'API call failed with cURL error: ' . curl_error($curlHandle)
);
}
// Clean up the resource now that we're done with cURL
curl_close($curlHandle);
// Decode the response from a JSON string to a PHP associative array
$apiResponse = json_decode($jsonEncodedApiResponse, true);
// Make sure we got back a well-formed JSON string and that there were no
// errors when decoding it
$jsonErrorCode = json_last_error();
if($jsonErrorCode !== JSON_ERROR_NONE) {
throw new \RuntimeException(
'API response not well-formed (json error code: ' . $jsonErrorCode . ')'
);
}
// Print out the response details
if($apiResponse['response']['status'] === 1) {
// No errors encountered
echo 'API call successful';
echo PHP_EOL;
echo 'Response Data: ' . print_r($apiResponse['response']['data'], true);
echo PHP_EOL;
}
else {
// An error occurred
echo 'API call failed (' . $apiResponse['response']['errorMessage'] . ')';
echo PHP_EOL;
echo 'Errors: ' . print_r($apiResponse['response']['errors'], true);
echo PHP_EOL;
}
?>
<script type="text/javascript">
<!--
function Redirect() {
window.location="index.php";
}
document.write("You will be redirected to main page in 2 sec.");
setTimeout('Redirect()', 2000);
//-->
</script>
代码补充: -
主要目标是我想用其他API更改这些记录的状态,为此我需要从一个复选框中获取两个值
提前致谢。
此致
答案 0 :(得分:0)
page1.php中:
<input name="v1" type="checkbox" class="checkbox" value="2681|14175">
使page2.php:
<?php
list($value1,$value2) = explode('|', $_GET['v1']);
echo "value1 = ".$value1.", value2 = ".$value2."<br>";
?>
请告诉我这是否对您有用!
答案 1 :(得分:0)
您可以使用以下代码获取此类网址
http://domainname.com/approve.php?type1=2681&type2=14175
if (isset($_POST['submit'])) {
$urldata=explode(":",$_POST['class'][0]);
}
?>
<form method="post" action='<?php if (isset($_POST['submit'])) {? >index.php? type1=<?php echo $urldata[0]."&type2=".$urldata[1] ?> <?php } ?>'>
<input name='class[]' type='checkbox' class='checkbox' value='55:1444'>
<input type="submit" name="submit" value="submit">
</form>