Why the list changes?

#1

the web script file that I’m trying to modify shows this:

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

which work with this:

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,
            'VIEWS_NUM' => number_format($video->views),
            'TIME' => $video->time_ago
            //'DURATION' => $video->duration
        ));
    }
}
if (empty($final)) {
	$final = $list;
}

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

which successfully displays the list of purchases on the ‘purchases’ html page.

I tried to add ‘time_date’ (purchase date) to that line like this:

$get_videos = $db->rawQuery("SELECT DISTINCT(v.id), v.* 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");

and changed to:

'TIME' => $video->time_date

Those changes successfully add the ‘time_date’ to the html page, but as a result of that change the displayed list on the ‘purchases’ html page are not the same list as before the changes. (I can’t really determine a common reason why these new displayed videos are on that page - as a result of that change).

Ideally, I’d like the ‘purchases’ to be displayed in order on latest purchase date.

Any assistance will be appreciated.

#2

WHERE… AND upv.time_date doesnt make logical sense. and time_date… what? exists? is greater than some value? What exactly are you trying to restrict your value set to by including time_date in the where clause?

#3

Thanks for your reply.
I was trying to get the purchase date to display on the ‘purchases’ html page, which it does successfully, but changes what is listed somehow. If what I have doesn’t make logical sense, can you provide an example of what would make more sense in that line?

#4

Before the if statement try the following which will display the query result:

echo '<pre>'; // adds linefeeds
  var_dump( $get_videos );
echo '</pre>';
die: // temporary halts script execution

Ensure the values are correct before remming the above script and proceeding to the if statement.

#5

So you were trying to SELECT an additional field. which means you should add it to the SELECT clause, not the WHERE clause.

SELECT defines what you want to retrieve in each row of results. WHERE defines which rows you want to include based on criteria.

$get_videos = $db->rawQuery("SELECT DISTINCT(v.id), v.*, upv.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} ORDER BY upv.id DESC");
1 Like
#6

Thank you for your replies.

I have tried:

$get_videos = $db->rawQuery("SELECT DISTINCT(v.id), v.*, upv.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} ORDER BY upv.id DESC");

and the result was that no date appeared on the html page. But, as stated earlier, this shows the date successfully but changes the displayed list of ‘purchases’:

$get_videos = $db->rawQuery("SELECT DISTINCT(v.id), v.* 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");

I also tried the other suggestion of adding:

echo '<pre>'; // adds linefeeds
  var_dump( $get_videos );
echo '</pre>';
die: // temporary halts script execution

like so:

  $get_videos = $db->rawQuery("SELECT DISTINCT(v.id), v.* 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");

echo '<pre>'; // adds linefeeds
  var_dump( $get_videos );
echo '</pre>';
die: // temporary halts script execution

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,
            'VIEWS_NUM' => number_format($video->views),
            'TIME' => $video->time_date
            //'DURATION' => $video->duration
        ));
    }
}

but the page is now blank.

Any additional help is welcomed.

#7

Shouldn’t this

die: // etc.

end with a semi-colon, like a normal PHP line of code, rather than a colon? I suspect it’s throwing a parse error.

1 Like
#8

Thank you for your message.
After correcting that semi-colon, I see this:

array(20) {
  [0]=>
  object(stdClass)#466 (42) {
    ["id"]=>
    int(193)
    ["video_id"]=>
    string(15) "vGN2uaVXpWhNicY"
    ["user_id"]=>
    int(2)
    ["short_id"]=>
    string(6) "PgbVov"
    ["title"]=>
    string(13) "4-052819Video"
    ["description"]=>
    string(3) "fff"
    ["thumbnail"]=>
    string(120) "upload/photos/2019/05/b47b70ff8b614e30f281b42f6c378b258b1509d4knKjj6XLPuGk1pubr1x.video_thumb_8764_33.jpeg"
    ["video_location"]=>
    string(103) "upload/videos/2019/05/lZ4YPzoR9MYUUsAVpB9T_28_cee897f745f55c7f2db13c61d64907qq_video_240p_converted.mp4"
    ["youtube"]=>
    string(0) ""
    ["vimeo"]=>
    string(0) ""
    ["daily"]=>
    string(0) ""
    ["facebook"]=>
    string(0) ""
    ["twitch"]=>
    string(0) ""
    ["twitch_type"]=>
    string(0) ""
    ["time"]=>
    int(1559060478)
    ["time_date"]=>
    string(19) "2019-05-28 12:21:18"
    ["active"]=>
    int(0)
    ["tags"]=>
    string(8) "ff,uu,cc"
    ["duration"]=>
    string(4) "0:10"
    ["size"]=>
    int(590043)
    ["converted"]=>
    int(1)
    ["category_id"]=>
    string(1) "1"
    ["sub_cat_id"]=>
    int(0)
    ["views"]=>
    int(1)
    ["featured"]=>
    int(0)
    ["registered"]=>
    string(6) "2019/5"
    ["privacy"]=>
    int(0)
    ["age_restriction"]=>
    int(1)
    ["type"]=>
    string(0) ""
    ["approved"]=>
    int(1)
    ["240p"]=>
    int(1)
    ["360p"]=>
    int(1)
    ["480p"]=>
    int(0)
    ["720p"]=>
    int(0)
    ["1080p"]=>
    int(0)
    ["2048p"]=>
    int(0)
    ["4096p"]=>
    int(0)
    ["credits"]=>
    NULL
    ["video_play_price"]=>
    NULL
    ["sell_video"]=>
    int(0)
    ["sub_category"]=>
    string(1) "0"
    ["geo_blocking"]=>
    string(0) ""
  }
  [1]=>
etc.....
[2]=>
thru [19]=>

I’m not sure what I’m looking for in this output.
Any additional assistance is appreciated

#9

Please accept my apologies for not mentioning the script was not tested because it was typed on an iPad.

The PHP page should have this error checking at the top to highlight any errors.

<?php
// local host, remove before uploading to online server
declare( strict_types=1 );
ini_set('display_errors', true);
error_reporting(-1);

// useful debugging script
// usage:
// fred( $val );  die;
function fred( $val )
{
echo '<pre>';
var_dump( $val );
echo '</pre>';
} // endfunc 

Beware: Not tested because typed on an ipad

Edit:

added function name

#10

Try stepping through the script using the debug function fred ( $val ); in my previous post.

Only continue when the variable results are what you expect otherwise go back and rectify the problem.

#11

Probably helps if you give that function a name though, instead of function ( $val ) - that’s a parse error :wink:

1 Like
#12

Whoops, now unable to rectify because editing period has elapsed :frowning:

I will be pleased to be back on a desktop instead of this tablet.