php - Passing multiple values in a url using checkbox -
i know may answered not able find related this. here thing struggling :-
i have 2 value passing in check box :-
<input name='class[]' type='checkbox' class='checkbox' value='".$x_value['type1'].":".$x_value['type2']."'>
on running :-
<input name="class[]" type="checkbox" class="checkbox" value="2681:14175">
so want how can pass these value separated ":" in url.
something :-
http://domainname.com/approve.php?type1=2681&type2=14175
purpose :-
actually getting value api response curl , generating multiple checkboxes. each checkbox contains 2 value separated ":".
now want run separate api in different file values url.
update : below complete code :-
<?php foreach($apiresponse['response']['data'] $x =>$x_value) { foreach($x_value $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>"; } } ?>
update no. 2 :-
api getting records :-
<!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 , respond.js ie8 support of html5 elements , media queries --> <!-- warning: respond.js doesn't work if view 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 can access response when execute call curl_setopt($curlhandle, curlopt_returntransfer, true); // execute api call $jsonencodedapiresponse = curl_exec($curlhandle); // ensure http call successful if($jsonencodedapiresponse === false) { throw new \runtimeexception( 'api call failed curl error: ' . curl_error($curlhandle) ); } // clean resource we're done curl curl_close($curlhandle); // decode response json string php associative array $apiresponse = json_decode($jsonencodedapiresponse, true); // make sure got well-formed json string , there no // errors when decoding $jsonerrorcode = json_last_error(); if($jsonerrorcode !== json_error_none) { throw new \runtimeexception( 'api response not well-formed (json error code: ' . $jsonerrorcode . ')' ); } // print out 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 { // 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'] $x =>$x_value) { // echo "affiliate id" . $x . ", value=" ; //print_r($x_value); foreach($x_value $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 bootstrap's javascript plugins) <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>--> <!-- include compiled plugins (below), or include individual files needed <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>--> </body> </html>
api change status of multiple records :-
second url become :-
http://www.domain.com/approve.php?offerid=123&affid=456
out of offer id , affid passed checkbox value
<?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 can access response when execute call curl_setopt($curlhandle, curlopt_returntransfer, true); // execute api call $jsonencodedapiresponse = curl_exec($curlhandle); // ensure http call successful if($jsonencodedapiresponse === false) { throw new \runtimeexception( 'api call failed curl error: ' . curl_error($curlhandle) ); } // clean resource we're done curl curl_close($curlhandle); // decode response json string php associative array $apiresponse = json_decode($jsonencodedapiresponse, true); // make sure got well-formed json string , there no // errors when decoding $jsonerrorcode = json_last_error(); if($jsonerrorcode !== json_error_none) { throw new \runtimeexception( 'api response not well-formed (json error code: ' . $jsonerrorcode . ')' ); } // print out 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 { // 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 redirected main page in 2 sec."); settimeout('redirect()', 2000); //--> </script>
code added :-
main objective want change status of records api, , need 2 value single checkbox
thanks in advance.
sincerely
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>"; ?>
let me know if worked you!
Comments
Post a Comment