In the php file this works successfully:
I’d like to add this data to a different table that has these columns:
id, user_id, paid_id, video_id, amount, admin_com, time
This replacement now works successfully:
However, I can’t seem to figure out how to have the (video) uploader’s id to populate the ‘videos_transactions’ table’s ‘user_id’ column.
Here’s the code up to the array:
any help with this is appreciated.
PHP:
// add data to table
$insert_buy = $db->insert('u_paid_videos', [
'id_user' => $user_id,
'video_play_price' => (string)$video_cost_new,
'id_video' => $video_id,
'user_id_uploaded' => $video->user_id,
'video_title' => $video->title,
'earned_amount' => $up_amount,
'time' => $time_start,
'short_id' => $video->short_id,
'session_key' => $_SESSION['session_key']
]);
I’d like to add this data to a different table that has these columns:
id, user_id, paid_id, video_id, amount, admin_com, time
This replacement now works successfully:
PHP:
// add data to table
$insert_buy = $db->insert(‘videos_transactions’, [
‘paid_id’ => $user_id,
‘video_id’ => $video_id,
//‘user_id’ => $user_id_uploaded,
‘amount’ => $video_cost_new,
‘admin_com’ => $uploader_amount,
‘time’ => $time_start
]);
However, I can’t seem to figure out how to have the (video) uploader’s id to populate the ‘videos_transactions’ table’s ‘user_id’ column.
Here’s the code up to the array:
PHP:
<?php
ob_start();
error_reporting(-1); // set maximum errors
error_reporting(E_ALL);
ini_set(‘display_errors’ , ‘true’);
if (IS_LOGGED == false) {
$data = array('status' => 400, 'error' => 'Not logged in');
echo json_encode($data);
exit();
}
if (!empty($_POST['id'])) {
if (!is_array($_POST['id'])) {
$id_array[] = $_POST['id'];
} else {
$id_array = $_POST['id'];
}
// get cost video
// get the default video price, to use if there is no per video play price
$db->where('name', 'video_play_price');
$db_cost = $db->getOne('config');
$video_cost = (float)$db_cost->value;
// the number of submitted videos - used to determine if all records were inserted
$count_video = count($id_array);
$user_id = $user->id;
$wallet = (float)str_replace(',', '', $user->wallet);
$balance = (float)str_replace(',', '', $user->balance);
// add up the video prices
$amount = 0;
foreach ($id_array as $id) {
$video_id = (int)PT_Secure($id);
// get video data
$video = $db->where('id', $id)->getOne(T_VIDEOS);
// add the video play price if any, or the default price
$amount += $video->video_play_price?$video->video_play_price:$video_cost;
}
// determine if the user has enough credits
if( ($wallet >= $amount) OR ($balance + $wallet >= $amount) ) {
$db->startTransaction();
$inserted_records = 0;
foreach ($id_array as $id){
$video_id = (int)PT_Secure($id);
// get video data
$video = $db->where('id', $id)->getOne(T_VIDEOS);
//$video = $db->where('short_id', $short_id)->getOne(T_VIDEOS);
// use the video play price if any, or the default price
$video_cost_new = $video->video_play_price?$video->video_play_price:$video_cost;
// credit the user 50% of the video cost
$uploader_amount = $video_cost_new *0.50;
$time_start = microtime(true);
//$time_start = date('Y-m-d H:i:s');
// add data to paid table
$insert_buy = $db->insert('videos_transactions', [
'paid_id' => $user_id,
'video_id' => $video_id,
//'user_id' => $user_id_uploaded,
'amount' => $video_cost_new,
'admin_com' => $uploader_amount,
'time' => $time_start
]);
any help with this is appreciated.