I'm working on getting the following block of code to send the array variable 'row' to another page. The other page should pull the vendor_id from this array and help populate a form with database information. I'm completely lost at how to accomplish this as I am relatively new to web dev. Can someone point me in the right direction?
function operateFormatter(value, row, index) {
return [
'<a class="remove" href="javascript:void(0)" title="Remove">',
'<i class="fa fa-trash"></i>',
'</a>',
'<a class="view" href="viewVendor.php" title="View">',
'<i class="fa fa-eye"></i>',
'</a>'
].join('')
}
window.operateEvents = {
'click .view': function (e, value, row, index) {
sessionStorage.setItem("vendor_id", JSON.stringify(row));
},
'click .remove': function (e, value, row, index) {
$table.bootstrapTable('remove', {
field: 'id',
values: [row.id]
})
}
}
viewVendor.php
<?php
include 'config.php';
require './db_inc.php';
$user = $_SESSION['username'];
## Fetch records
$stmt = $conn->prepare("SELECT * FROM vendor_data");
$stmt->execute();
$Records = $stmt->fetchAll();
$data = array();
foreach($Records as $row){
$data[] = array(
"name"=>$row['name'],
"company"=>$row['company'],
"type"=>$row['type'],
"status"=>$row['status'],
"owner"=>$row['owner'],
"descr"=>$row['descr'],
"owner_email"=>$row['owner_email'],
"dept"=>$row['dept']
);
}
return json_encode(($data));
?>
<script>
alert(sessionStorage.getItem("vendor_id[1]"));
</script>
I have a php page that includes the above mentioned viewVendor.php file which should pass along the information. Maybe I'm over complicating things?
You could add the vendor_id to the query string in your a tag like (assuming 'row' is the vendor id value):
'<a class="view" href="viewVendor.php?vendor_id=' + row + '" title="View">',
Then in your viewVendor.php file, access it with:
$_GET['vendor_id']
Though you may want to validate the vendor id in the PHP if it's going to be used to query your db.