ajax - 如何通过获取他/她的用户 ID 将资金转移给特定用户?(代码点火器)
问题描述
新手来了 我的目标是得到ID
我要转移的人的。例如:His userID
= 4。userID
在我的数据库userID
列中应该是 = 4。我在下面提供了屏幕截图以便更好地解释。先感谢您
https://prnt.sc/w9piat << 我的问题和我的目标的截图
意见:
<button data-id="<?php echo $rows->userID; ?>" class=" fundTable btn btn-success btn-sm text-bold " type="button" data-toggle="modal" data-target="#fundModal">
<i class="fas fa-hand-holding-usd mr-1"></i> <?php echo $rows->userID; ?>FUND
</button>
控制器:
public function form_validation()
{
$this->load->library('form_validation');
$this->form_validation->set_rules("amount","Amount", 'required|numeric');
if($this->form_validation->run())
{
$ref= $this->session->userdata('userID') + time ();
$data = array(
'userID' => $this->session->userdata('uid'),
'transactionSource' => 'fund',
'refNumber' => 'FI' . $ref,
"amount" =>$this->input->post("amount"),
"transType" =>"in",
);
$ref= $this->session->userdata('userID') + time ();
$data1 = array(
'userID' => $this->session->userdata('uid'),
"transactionSource" => 'fund',
"refNumber" => 'FO' . $ref,
"amount" =>$this->input->post("amount"),
"transType" =>"out",
);
$this->networks->insert_data($idata, $idata1);
redirect(base_url() . "network/agents");
}
else
{
$this->index();
}
}
型号:
function insert_data($data,$data1)
{
$sql1 = "select * from transaction_ledger where userID = ? order by ledgerID desc limit 0,1";
$Q1 = $this->db->query($sql1, $data['userID']);
$R1 = $Q1->row_array();
$ref= $this->session->userdata('userID') + time ();
$idata = array(
'userID' => $data['userID'],
'transactionSource' => 'Fund',
'transType' => 'out',
'refNumber' => 'FO' . $ref,
'amount' => $data['amount'],
'currentBalance' => $R1['currentBalance'] - $data['amount'],
'previousBalance' => $R1['currentBalance'],
);
$this->db->insert('transaction_ledger', $idata);
//update current wallet
$sqlUpdate = "update users set currentPoints = '".$idata['currentBalance']."', dateUpdated = '".date('Y-m-d h:i:s')."'where userID = ?";
$this->db->query($sqlUpdate, $data['userID']);
//update you will get the fund
$idata1 = array(
// 'userID' => $data['userID'], (My target is, the ID of the person that i will transfer the fund. How can i get his/her ID?
'transactionSource' => 'Fund',
'transType' => 'in',
'refNumber' => 'FI' . $ref,
'amount' => $data['amount'],
'currentBalance' => $R1['currentBalance'] + $data['amount'],
'previousBalance' => $R1['currentBalance'],
);
$this->db->insert('transaction_ledger', $idata1);
$sqlUpdate = "update users set currentPoints = '".$idata1['currentBalance']."', dateUpdated = '".date('Y-m-d h:i:s')."'where userID=0";
$this->db->query($sqlUpdate, $data['userID']);
}
}
解决方案
在您的模态表单中添加一个隐藏字段,其中包含您要资助的用户的 ID。每次单击“资金”按钮时,您都会获得该按钮的 ID,然后将其添加到模态表单隐藏字段中,这样您就可以将该值与金额一起传递。
<!-- 5 is the id person that going to transfer with -->
<button data-id="7" class="showmodal" class="fundTable btn btn-success btn-sm text-bold">
<i class="fas fa-hand-holding-usd mr-1"></i> 5 FUND
</button>
<div id="fundModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="#">
<input type="text" id="usertransferid">
<input type="number" id="amount">
</form>
<p>Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
推荐阅读
- python - 如何在keras的最后一层输入单个变量?
- urlencode - 在后续请求中使用之前对字符串进行 URL 编码 (Gatling)
- rust - 返回闭包的函数的正确语法
- d - 不能在 char 数组上使用并行?
- javascript - 如何将 JavaScript 变量与 PHP 生成的 JSON 绑定?
- c++ - C++ C 样式数组大小限制
- mariadb - MariaDB HAProxy 死锁
- firebase - Flutter Firebase教程错误
- python - seaborn histplot 中的均值和中线
- android - 如何在 Android 中更改房间数据库中的实体类文件