Kahif Posted February 14, 2023 Share Posted February 14, 2023 Helo everyone i am using the following code to get views regarding visits <li><span class="cmp_button_wire" ><i class="fa fa.eye"></i>{$article->getViews()}</span></li> please help me how to add 1000 in each view, i mean the display must show a number (views count) with addition of 1000 e.g., if there are 34 views in actual, it should show 1034 Regards. Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/ Share on other sites More sharing options...
Barand Posted February 14, 2023 Share Posted February 14, 2023 You use the "+" operator to add two numbers together. Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605649 Share on other sites More sharing options...
Kahif Posted February 14, 2023 Author Share Posted February 14, 2023 can you please guide the exact code that i will replace Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605650 Share on other sites More sharing options...
Kahif Posted February 14, 2023 Author Share Posted February 14, 2023 where i have to put the "+" operator in the code <li><span class="cmp_button_wire" ><i class="fa fa.eye"></i>{$article->getViews()}</span></li> Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605651 Share on other sites More sharing options...
ginerjm Posted February 14, 2023 Share Posted February 14, 2023 If this were part of a PHP script it could look like this:< // assuming already in PHP mode $cnt = $article->getViews(); $newcnt = $cnt + 1000; echo "<li> <span class='cmp_button_wire'> <i class='fa fa.eye'>$newcnt</i> </span> </li>"; How you update the $newcnt into where $article is another topic. PS - I corrected your italics tag. The better way is to use CSS for that instead of the old <i> tag. Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605653 Share on other sites More sharing options...
Psycho Posted February 14, 2023 Share Posted February 14, 2023 To add some context to @Barand's response. The code you provided is not "complete". I would expect that line is contained within an echo statement that uses double quotes. Within a string defined with double quotes the brace {} characters have special meaning - they allow you to include a PHP variable directly within the quoted string. But, you cannot manipulate the variable within the braces - only include the value of it. So, similar to what Barand showed, you need to find where that string starts and before the declaration of the string you will want to define a new variable which is the view count +1000. Then replace the view count variable within the quoted string with the new variable that you have defined. Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605654 Share on other sites More sharing options...
Kahif Posted February 14, 2023 Author Share Posted February 14, 2023 Everyone I am really thankful for the nice help I am going to share the complete code as below {** * templates/frontend/objects/article_summary.tpl * * Copyright (c) 2014-2021 Simon Fraser University * Copyright (c) 2003-2021 John Willinsky * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. * * @brief View of an Article summary which is shown within a list of articles. * * @uses $article Article The article * @uses $hasAccess bool Can this user access galleys for this context? The * context may be an issue or an article * @uses $showDatePublished bool Show the date this article was published? * @uses $hideGalleys bool Hide the article galleys for this article? * @uses $primaryGenreIds array List of file genre ids for primary file types * @uses $heading string HTML heading element, default: h2 *} {assign var=articlePath value=$article->getBestId()} {if !$heading} {assign var="heading" value="h2"} {/if} {if (!$section.hideAuthor && $article->getHideAuthor() == $smarty.const.AUTHOR_TOC_DEFAULT) || $article->getHideAuthor() == $smarty.const.AUTHOR_TOC_SHOW} {assign var="showAuthor" value=true} {/if} {assign var=publication value=$article->getCurrentPublication()} <div class="obj_article_summary"> {if $publication->getLocalizedData('coverImage')} <div class="cover"> <a {if $journal}href="{url journal=$journal->getPath() page="article" op="view" path=$articlePath}"{else}href="{url page="article" op="view" path=$articlePath}"{/if} class="file"> {assign var="coverImage" value=$article->getCurrentPublication()->getLocalizedData('coverImage')} <img src="{$article->getCurrentPublication()->getLocalizedCoverImageUrl($article->getData('contextId'))|escape}" alt="{$coverImage.altText|escape|default:''}" > </a> </div> {/if} <{$heading} class="title"> <a id="article-{$article->getId()}" {if $journal}href="{url journal=$journal->getPath() page="article" op="view" path=$articlePath}"{else}href="{url page="article" op="view" path=$articlePath}"{/if}> {$article->getLocalizedTitle()|strip_unsafe_html} {if $article->getLocalizedSubtitle()} <span class="subtitle"> {$article->getLocalizedSubtitle()|escape} </span> {/if} </a> </{$heading}> {if $showAuthor || $article->getPages() || ($article->getDatePublished() && $showDatePublished)} <div class="meta"> {if $showAuthor} <div class="authors"> {$article->getAuthorString()|escape} </div> {/if} {* Page numbers for this article *} {if $article->getPages()} <div class="pages"> {$article->getPages()|escape} </div> {/if} {if $showDatePublished && $article->getDatePublished()} <div class="published"> {$article->getDatePublished()|date_format:$dateFormatShort} </div> {/if} </div> {/if} {if !$hideGalleys} <ul class="galleys_links"> {$cnt = $article->getViews; $newcnt = $cnt + 1000;} echo "<li> <span class='cmp_button_wire'> <i class='fa fa.eye'>$newcnt</i> </span> </li>"; {foreach from=$article->getGalleys() item=galley} {if $primaryGenreIds} {assign var="file" value=$galley->getFile()} {if !$galley->getRemoteUrl() && !($file && in_array($file->getGenreId(), $primaryGenreIds))} {continue} {/if} {/if} <li> {assign var="hasArticleAccess" value=$hasAccess} {if $currentContext->getSetting('publishingMode') == $smarty.const.PUBLISHING_MODE_OPEN || $publication->getData('accessStatus') == $smarty.const.ARTICLE_ACCESS_OPEN} {assign var="hasArticleAccess" value=1} {/if} {include file="frontend/objects/galley_link.tpl" parent=$article labelledBy="article-{$article->getId()}" hasAccess=$hasArticleAccess purchaseFee=$currentJournal->getData('purchaseArticleFee') purchaseCurrency=$currentJournal->getData('currency')} </li> {/foreach} </ul> {/if} {call_hook name="Templates::Issue::Issue::Article"} </div> Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605655 Share on other sites More sharing options...
Kahif Posted February 14, 2023 Author Share Posted February 14, 2023 i have used the segment as below {$cnt = $article->getViews; $newcnt = $cnt + 1000;} echo "<li> <span class='cmp_button_wire'> <i class='fa fa.eye'>$newcnt</i> </span> </li>" but its not working😴 Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605656 Share on other sites More sharing options...
ginerjm Posted February 14, 2023 Share Posted February 14, 2023 (edited) It should be showing the same 'new' value every time since we are not saving it afterwards yet. Try this: $cnt = $article->getViews(); $newcnt = $cnt + 1000; echo "old cnt $cnt; new cnt $newcnt<br>"; echo "<li> <span class='cmp_button_wire'> <i class='fa fa.eye'>$newcnt</i> </span> </li>" see what you get out of that Edited February 14, 2023 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605657 Share on other sites More sharing options...
Kahif Posted February 14, 2023 Author Share Posted February 14, 2023 @ginerjmI am really grateful for your great help but unfortunately its not working........ Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605660 Share on other sites More sharing options...
ginerjm Posted February 14, 2023 Share Posted February 14, 2023 (edited) Did you see the echo output that I put in there? Can I see That block of code please? Not the whole thing which I woudn't even look at. Just a little that will give me some context. BTW - do you have error checking enabled? When you say not working does it at least display when you run it? Just ran a test of the code. There is an error in my code which you are not picking up apparently. Turn on error checking or if by not working you mean that you see absolutely nothing on your screen. Edited February 14, 2023 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605661 Share on other sites More sharing options...
Barand Posted February 14, 2023 Share Posted February 14, 2023 @ginerjmWhy have you suggested putting the $newcount in the middle of a Font-Awesome icon? Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605662 Share on other sites More sharing options...
ginerjm Posted February 14, 2023 Share Posted February 14, 2023 I assumed that it was an italics tag that s/b showing the new value. Figured if it was outside the <i></i>then it served no purpose. Have no idea what "font awesome" is BTW. Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605663 Share on other sites More sharing options...
Kahif Posted February 14, 2023 Author Share Posted February 14, 2023 The line below is showing the actual number of count without addition of 1000 and working fine <li><span class="cmp_button_wire" ><i class="fa fa.eye"></i>{$article->getViews()}</span></li> but how to add 1000 in each count Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605664 Share on other sites More sharing options...
ginerjm Posted February 14, 2023 Share Posted February 14, 2023 (edited) That's the part I said you have to do. I certainly don't know what your app is doing and I'm not going thru the entire block you posted. Is this thing using a db? Find the logic that uses the $article's class and see what methods it has. It has a getview one so maybe it has an "updateview" method. Edited February 14, 2023 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605666 Share on other sites More sharing options...
Kahif Posted February 14, 2023 Author Share Posted February 14, 2023 I am adding it diectly in cpanel and it is using a DB, ok let me to see if the "updateview" work or not BTW, please tel me how to embed updateview in this code?? Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605667 Share on other sites More sharing options...
Barand Posted February 14, 2023 Share Posted February 14, 2023 15 minutes ago, ginerjm said: Have no idea what "font awesome" is BTW. Strange, because I gave you an example about 3 weeks ago Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605668 Share on other sites More sharing options...
ginerjm Posted February 14, 2023 Share Posted February 14, 2023 You gave that to someone to help but I had no interest in whatever it was/is. Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605669 Share on other sites More sharing options...
ginerjm Posted February 14, 2023 Share Posted February 14, 2023 12 minutes ago, Kahif said: BTW, please tel me how to embed updateview in this code?? Since I have no knowledge this class you are using (at least I am assuming it is a class) I really can't help you. But look a the docs for it and see what methods are provided. Than add it to the php section after you have done the update and display. If it's just a one line call to a method you could insert it right after the logic I gave you. Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605670 Share on other sites More sharing options...
Kahif Posted February 14, 2023 Author Share Posted February 14, 2023 Thnak you Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605671 Share on other sites More sharing options...
Barand Posted February 14, 2023 Share Posted February 14, 2023 I haven't used Smarty, but does this work? <li><span class="cmp_button_wire" ><i class="fa fa.eye"></i>{$article->getViews() + 1000}</span></li> Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605672 Share on other sites More sharing options...
Barand Posted February 14, 2023 Share Posted February 14, 2023 21 minutes ago, ginerjm said: You gave that to someone to help but I had no interest in whatever it was/is. You were quoted in that reply - it was response to one of your statements (the last time that you were sounding off about deprecated italics tags). Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605674 Share on other sites More sharing options...
ginerjm Posted February 14, 2023 Share Posted February 14, 2023 Well thank you for pointing that out. But I still am clueless about what it is doing there and I don't think I have any need to learn about it. Quote Link to comment https://forums.phpfreaks.com/topic/315912-php-counter/#findComment-1605676 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.