如何通过获取特定用户的用户ID将资金转移给该用户?(Codeigniter)



这里是新手。我的目标是获得要和我一起调动的人的ID。例如:他的userID=4。我的数据库userID列中的userID应为=4。为了更好的解释,我提供了下面的截图。提前感谢

https://prnt.sc/w9piat<lt;我的问题和目标的屏幕截图

视图

<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">&times;</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>

你可以在这里测试https://jsfiddle.net/renzuii/tvnjf172/

最新更新