Jump to content
Chrisj

Adding a number under the thumbnail

Recommended Posts

I am using a php web video script which, when searched, displays a list of thumbnail image search results, with a View button, below each image. I'm trying to add the numeric price under each one, but haven't gotten it correct yet. Here is the list.html page code:

<div class="col-md-3 col-sm-6 no-padding-right-at-all no-padding-mobile-left">
	<div class="video-latest-list video-wrapper" data-id="{{ID}}" data-views="{{VIEWS}}">
		<div class="video-thumb">
			<img src="{{THUMBNAIL}}" alt="{{TITLE}}">
			<div class="video-duration">{{DURATION}}</div>
		</div>
		<div class="video-title">
			<h4 title="{{TITLE}}">{{TITLE}}</h4>
		</div>
		<div class="video-info">
			<div style="float:right;"><button class="btn btn-main" data-action="multiple_select_button" data-selected="0" data-id="{{ID}}">View</button></div>
			<div class style="float:left;" data-id="{{ID}}">{{VIDEOS video_play_price}}</div>
		</div>
	</div>
</div>

In my attempt to display the price, added this line:

<div class style="float:left;" data-id="{{ID}}">{{VIDEOS video_play_price}}</div>

I am assuming the data-id="{{ID}}" identifies the particular thumbnail/video? and I know that the current price resides in the 'videos' table, in the db, under the column titled 'video_play_price', but with my line of code the only thing that appears under the thumbnail is {{VIDEOS video_play_price}} (as you probably know). Any help to display the numeric price pertaining to each video(thumbnail), will be appreciated.

 

Edited by Chrisj

Share this post


Link to post
Share on other sites

It's going to be hard for you to do this if you don't understand what you're working with.

Those {{ }}s are not PHP code. Obviously. Something else is searching for them in your HTML and replacing them with values. What is it, and how are the ID and VIEWS and THUMBNAIL and so on getting values from your database?

Share this post


Link to post
Share on other sites

Thanks for your reply. I believe this file corresponds with the initial code I posted. Does this help:

 

<?php

include('/assets/langs/english.php');
if (empty($_GET['keyword'])) {
    header("Location: " . PT_Link('login'));
    exit();
}
$keyword = PT_Secure($_GET['keyword']);
$category_id = (isset($_GET['category_id'])?$_GET['category_id']:0);

$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_for_now . '</div>';
$list2 = '<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></div>';
$final = '';

if ($pt->config->total_videos > 1000000) {
    if($category_id == 0){
        $get_videos = $db->rawQuery("SELECT * FROM " . T_VIDEOS . " WHERE  MATCH (title) AGAINST ('$keyword') OR tags LIKE '%$keyword%' ORDER BY id ASC LIMIT 20");
    }else{
        $get_videos = $db->rawQuery("SELECT * FROM " . T_VIDEOS . " WHERE category_id=$category_id AND ( MATCH (title) AGAINST ('$keyword') OR tags LIKE '%$keyword%' ) ORDER BY id ASC LIMIT 20");
    }
    
} else {
    if($category_id == 0){
        $get_videos = $db->rawQuery("SELECT * FROM " . T_VIDEOS . " WHERE title LIKE '%$keyword%' OR tags LIKE '%$keyword%'  ORDER BY id ASC LIMIT 20");
    }else{
        $get_videos = $db->rawQuery("SELECT * FROM " . T_VIDEOS . " WHERE category_id=$category_id AND ( title LIKE '%$keyword%' OR tags LIKE '%$keyword%' )  ORDER BY id ASC LIMIT 20");
    }
    
}

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('search/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;
}

$get_users = $db->rawQuery("SELECT * FROM " . T_USERS . " WHERE ((`username` LIKE '%$keyword%') OR CONCAT( `first_name`,  ' ', `last_name` ) LIKE  '%$keyword%') ORDER BY id ASC LIMIT 50");
if (!empty($get_users)) {
    $len = count($get_users);
    foreach ($get_users as $key => $user) {
        $user = PT_UserData($user, array('data' => true));
        $pt->last_user = false;
        if ($key == $len - 1) {
            $pt->last_user = true;
        }
        $final2 .= PT_LoadPage('search/user-list', array(
            'ID' => $user->id,
            'USER_DATA' => $user,
        ));
    }
}

if (empty($final2)) {
    $final2 = $list2;
}


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

 

Share this post


Link to post
Share on other sites

Yes, that's it.

Add a PRICE to the list of values it supports, then put a {{ PRICE }} in the HTML where you want it to appear.

Share this post


Link to post
Share on other sites

Thanks so much for your guidance. Greatly appreciated.

 

I added 'PRICE" etc., this to the php:

 

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('search/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,
            'PRICE' => $video_play_price

        ));
    }
}
if (empty($final)) {
    $final = $list;
}

Then I replaced the html line to look like this:

 

<div class style="float:left;" data-id="{{ID}}">{{PRICE}}</div>

But only see {{PRICE}} displayed. Any suggestion on what I've done incorrectly, will be welcomed. Much thanks again

 

 

Share this post


Link to post
Share on other sites

Then there's something else you haven't found yet. Maybe caching, maybe precompiled views, maybe there's something else you have to edit, basically all I can do is guess.

Share this post


Link to post
Share on other sites

Ok, yes, thanks a lot for your replies/help. I realized it worked for some particular videos. 
When a video is uploaded, the price reflected in the Admin-panel is the default price. After upload, a logged-in uploader can change the price, in their my-account > manage-videos area. It appears that the only numeric {{PRICE}} that is now successfully displaying, in the search results, is the price changed by the uploader, the rest of the displayed results show no price.

So, your great help was correct, but, now how to get the default price to display is the next mystery. This is the buy-video.php file code (below). Maybe that would help determine how to display the default price (if applicable), in the search results, too:

 

<?php
ob_start();
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
    $db->where('name', 'video_play_price');
    $db_cost = $db->getOne('config');
    $video_cost = (float)$db_cost->value;

    $count_video = count($id_array);
    $user_id = $user->id;
    $wallet = (float)str_replace(',', '', $user->wallet);


	$amout = 0;
	foreach ($id_array as $id) {
            $video_id = (int)PT_Secure($id);

            // get video data
            $video = $db->where('id', $id)->getOne(T_VIDEOS);
			$amout += $video->video_play_price?$video->video_play_price:$video_cost;
	}

//   $amout = $video_cost * $count_video;

    $charge = ( $video_cost *0.50 );


    if ($wallet >= $amout) {

        //$new_wallet = (string)($wallet - $amout);
        $wallet = (string)($wallet - $amout);

        $db->startTransaction();

        $inserted_records = 0;
        foreach ($id_array as $id) {
            $video_id = (int)PT_Secure($id);


		// $uploader_amount = $video_cost - $charge; //100 - 20% = 80

            // get video data
            $video = $db->where('id', $id)->getOne(T_VIDEOS);



			$video_cost_new = $video->video_play_price?$video->video_play_price:$video_cost;

			$uploader_amount = ( $video_cost_new *0.50 );
            // add data to paid table
            $insert_buy = $db->insert('u_paid_videos', [
                'id_user' => $user_id,
                'id_video' => $video_id,
                'session_key' => $_SESSION['session_key'],
                'video_play_price' => (string)$video_cost,
                'video_title' => $video->title,
                'user_id_uploaded' => $video->user_id,
                //'up_credit'=>$video_cost,
                'up_credit'=>$uploader_amount,
            ]);

            if ($insert_buy) { $inserted_records++; }
            //add wallet users' video
        $userwallet = $db->where('id', $video->user_id)->getOne(T_USERS);


        //$videouserwallet = $userwallet->balance+$video_cost;
        $videouserwallet = $userwallet->balance+$uploader_amount;
        $db->where('id', $video->user_id);
        $update_balance = $db->update(T_USERS, [
          // 'wallet' => $videouserwallet,
            'balance' => number_format($videouserwallet, 2, '.', ''),
        ]);
        }


        $db->where('id', $user_id);
        //$update_wallet = $db->update(T_USERS, [
        $update_wallet = $db->update(T_USERS, [
            'wallet' => $wallet,
        ]);


        if (($inserted_records == $count_video) && $update_wallet) {
            $db->commit();

            echo json_encode([
                'status' => 200
            ]);
            exit();
        } else {
            $db->rollback();

            echo json_encode([
                'status' => 400,
                'error' => 'Buy process error'
            ]);
            exit();
        }

    } else {

        echo json_encode([
            'status' => 400,
            'error_num' => 1,
            'error' => 'Not enough money'
        ]);
        exit();

    }

} else {

    echo json_encode([
        'status' => 400,
        'error' => 'Bad Request, Invalid or missing parameter'
    ]);
    exit();

echo('$video_play_price: '.$video_play_price.PHP_EOL);
echo('$charge: '.$charge.PHP_EOL);
echo('$amout: '.$amout.PHP_EOL);
$uploader_amount = $video_play_price - $charge;
$uploader_amount = $amout - $charge;
exit;


echo "$uploader_amount";
}

 

Edited by Chrisj

Share this post


Link to post
Share on other sites

Set the PRICE value to be whatever was set, or the default value if one wasn't set.

Share this post


Link to post
Share on other sites

Thanks again for your reply.
Yes, I'm not sure how/where to Set the PRICE value to be whatever was set, or the default value if one wasn't set.

I'm not sure, for example, what code defines 'default' price

Share this post


Link to post
Share on other sites

It's your code. You are going to have to learn how it works.

Share this post


Link to post
Share on other sites

This doesn't work, but it might be close?

 

'PRICE' => $video->number_format($video->video_play_price?$video->video_play_price:$config['video_play_price'],2),

 

Share this post


Link to post
Share on other sites

Actually yes, it is close.

But you want the number_format function, not a "number_format" method on the $video object (least not because it doesn't exist).

Share this post


Link to post
Share on other sites

Thanks again for your reply. After searching to try to get an idea of what you’re telling me, I don’t know what to do with that line of code. Any additional help will be appreciated 

Share this post


Link to post
Share on other sites

number_format is a function. You do know what a function is, right? It's not related to $video. Just a regular function.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.