Helping with substituting code to have page array populate

The web script that I’m using has a blank page that I’m trying to populate with data substituted from another db table named “u_paid_videos”, I’ve modified the existing file and tried numerous things without success. Maybe you can make suggestions as to how to get data from u_paid_videos’ to work with paid-videos/list’, array:

<?php
//if (IS_LOGGED == false || $pt->config->sell_videos_system == 'off' ) {
if (IS_LOGGED == false ) {
    header("Location: " . PT_Link('login'));
    exit();
}

$list = '<div class="text-center no-content-found empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-video-off"><path d="M16 16v1a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2m5.66 0H14a2 2 0 0 1 2 2v3.34l1 1L23 7v10"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg>' . $lang->no_videos_found_paid . '</div>';
$final = '';
//$type = 'videos';

//if (!empty($_GET['type']) && $_GET['type'] == 'movies' && $pt->config->movies_videos == 'on') {
   // $get = $db->rawQuery('SELECT * FROM '.T_VIDEOS_TRSNS.' t WHERE `paid_id` = '.$user->id.' AND (SELECT id FROM '.T_VIDEOS.' WHERE id = t.video_id AND `is_movie` = 1 AND user_id NOT IN ('.implode(",", $pt->blocked_array).')) = video_id ORDER BY id DESC LIMIT 20');
   // $type = 'movies';

//}
//else{
  //  $get = $db->rawQuery('SELECT * FROM '.T_VIDEOS_TRSNS.' t WHERE `paid_id` = '.$user->id.' AND (SELECT id FROM '.T_VIDEOS.' WHERE id = t.video_id AND `is_movie` != 1 AND user_id NOT IN ('.implode(",", $pt->blocked_array).')) = video_id ORDER BY id DESC LIMIT 20');
   //$get = $db->where('paid_id', $user->id)->orderby('id', 'DESC')->get(T_VIDEOS_TRSNS, 20);

//}
//$get_paid_videos = array();
//if (!empty($get)) {
   // foreach ($get as $key => $video_) {
     //  $fetched_video = $db->where('id', $video_->video_id)->getOne(T_VIDEOS);
     //  if (!empty($fetched_video)) {
          // $fetched_video->tr_id = $video_->id;
          // $get_paid_videos[] = $fetched_video;
      // }
    //}
//}

$get_videos = array();
if (!empty($get)) {
    foreach ($get as $key => $video_) {
      // $fetched_video = $db->where('id', $video_->video_id)->getOne(T_VIDEOS);
       $fetched_video = $db->where('id', $video_->id_video)->getOne(u_paid_videos);
       if (!empty($fetched_video)) {
           $fetched_video->tr_id = $video_->id;
           $get_videos[] = $fetched_video;
       }
    }
}

 //$get_videos = $db->rawQuery("SELECT DISTINCT(v.id), v.*, upv.trans as paid_user, upv.time_date as time_date FROM u_paid_videos AS upv LEFT JOIN " . T_VIDEOS . " AS v ON (upv.id_video = v.id) WHERE upv.id_user = {$user->id} AND upv.time_date ORDER BY upv.id DESC");

//if (!empty($get_paid_videos)) {
    //$len = count($get_paid_videos);
   // foreach ($get_paid_videos as $key => $video) {

   if (!empty($get_videos)) {
        $len = count($get_videos);
    foreach ($get_videos as $key => $video) {
        $video = PT_GetVideoByID($video, 0, 0, 0);
        $pt->last_video = false;
        if ($key == $len - 1) {
            $pt->last_video = true;
        }
        $final .= PT_LoadPage('paid-videos/list', array(
            'ID' => $video->tr_id,
            'USER_DATA' => $video->owner,
            'THUMBNAIL' => $video->thumbnail,
            'URL' => $video->url,
            'TITLE' => $video->title,
            'DESC' => $video->markup_description,
            'VIEWS' => $video->views,
            'TIME' => $video->time_ago,
            'VIDEO_ID_' => PT_Slug($video->title, $video->video_id),
           // 'GIF' => $video->gif
        ));
    }
}
if (empty($final)) {
	$final = $list;
}
$pt->page_url_ = $pt->config->site_url.'/paid-videos?type='.$type;
$pt->videos      = $get_videos;
//$pt->videos      = $get_paid_videos;
$pt->page        = 'paid-videos';
$pt->title       = $lang->paid_videos . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = $pt->config->keyword;
$pt->content     = PT_LoadPage('paid-videos/content', array(
    //'PAID_LIST' => $final
    'VIDEOS' => $final,
    'KEYWORD' => $keyword
));

any help is appreciated

Try adding these lines at the very start of the script and see if there are any errors or warnings.

<?php //
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', '1');

// Also call the following to display variable values 
// and see if they are what you expect;
 // <pre> adds line feeds to make it easier to view
echo '<pre>'; print_r($variable); echo '</pre>';

Many thanks for your reply/assistance.

I added your suggested code to the top of the file, and also added the ‘echo’ code (line 81) towards the bottom :

echo '<pre>'; print_r($variable); echo '</pre>';
$pt->page_url_ = $pt->config->site_url.'/paid-videos?type='.$type;
$pt->videos      = $get_videos;
//$pt->videos      = $get_paid_videos;
$pt->page        = 'paid-videos';
$pt->title       = $lang->paid_videos . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = $pt->config->keyword;
$pt->content     = PT_LoadPage('paid-videos/content', array(
    //'PAID_LIST' => $final
    'VIDEOS' => $final,
    //'KEYWORD' => $keyword
));

and this is what I see:

Notice: undefined variable: variable in /home/public_html/…/content.php on line 81
Notice: Undefined variable: type in /home/public_html/…/content.php on line 82

so, I removed the ‘echo’ line and modified line 82 to this:

$pt->page_url_ = $pt->config->site_url.'/paid-videos';

and when I refresh I see the page not populating, but no errors/notices/warnings.

I added this back:

echo '<pre>'; print_r($get_videos); echo '</pre>';

I see this:

Array
(
)

Any additional help is welcomed.

I forgot to mention that that $variable was to be replaced with any variable that requires checking. Also followed by die; which halts the script.

Try this: before the foreach loop because I don’t see $get declared anywhere?

echo '<br>' .__LINE__ .'<br>';
echo '<pre>'; print_r($get); echo '</pre>';
echo '<pre>'; print_r($_GET); echo '</pre>';
die;
if (!empty($get)) {
///

Thanks again. There is some progress, the code looks like this now:

//$get_videos = array();
//if (!empty($get)) {
    //foreach ($get as $key => $video_) {
      // $fetched_video = $db->where('id', $video_->video_id)->getOne(T_VIDEOS);
      // $fetched_video = $db->where('id', $video_->id_video)->getOne(u_paid_videos);
     //  if (!empty($fetched_video)) {
         //  $fetched_video->tr_id = $video_->id;
          // $get_videos[] = $fetched_video;
       //}
   // }
//}

 $get_videos = $db->rawQuery("SELECT DISTINCT(v.id), v.*, upv.trans as paid_user, upv.time_date as time_date FROM u_paid_videos AS upv LEFT JOIN " . T_VIDEOS . " AS v ON (upv.id_video = v.id) WHERE upv.id_user = {$user->id} AND upv.time_date ORDER BY upv.id DESC");

//if (!empty($get_paid_videos)) {
    //$len = count($get_paid_videos);
   // foreach ($get_paid_videos as $key => $video) {

   if (!empty($get_videos)) {
        $len = count($get_videos);
    foreach ($get_videos as $key => $video) {
        $video = PT_GetVideoByID($video, 0, 0, 0);
        $pt->last_video = false;
        if ($key == $len - 1) {
            $pt->last_video = true;
        }
        $final .= PT_LoadPage('paid-videos/list', array(
            'ID' => $video->id,
            'USER_DATA' => $video->owner,
            'THUMBNAIL' => $video->thumbnail,
            //'URL' => $video->url,
            'TITLE' => $video->title,
            'DESC' => $video->markup_description,
            'VIEWS' => $video->views,
            'TIME' => $video->time_ago,
            'VIDEO_ID_' => PT_Slug($video->title, $video->video_id),
           'PAID_USER' => "$video->id-$video->short_id-$video->time_date"
          // 'GIF' => $video->gif
        ));
    }
}
if (empty($final)) {
	$final = $list;
}
//echo '<pre>'; print_r($get_videos); echo '</pre>';
//die;

$pt->page_url_ = $pt->config->site_url.'/paid-videos';
$pt->videos      = $get_videos;
//$pt->videos      = $get_paid_videos;
$pt->page        = 'paid-videos';
$pt->title       = $lang->paid_videos . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = $pt->config->keyword;
$pt->content     = PT_LoadPage('paid-videos/content', array(
    //'PAID_LIST' => $final
    'VIDEOS' => $final,
    //'KEYWORD' => $keyword
));

and it populates the page, but has this Notice repeatedly:

Notice: Trying to get property of non-object in /home/public_html/…/functions_one.php on line 283

Line 283 (and 284) of that file is:

 if ($get_video->owner->id == $pt->user->id || PT_IsAdmin()) {
                $get_video->is_owner           = true;

any help with remedying this Notice, so it disappears is appreciated.

Just before that line, try using echo to show the values of each of the variables in the lines causing the error. Do it on separate lines, and you’ll see which of them is throwing the error by the line that shows the extra error.

Because it throws on both those lines, I suspect there is a problem with $get_video inside your function, as it’s the only object that appears on both lines. If this is inside a function, check how it is being passed in to make sure it is correct.