TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-13-2008, 10:43 PM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default Never ending increment?

I probably sound like a noob for this cause I never tried it. :P
Usually when incrementing, it only increments by one, but I want it to keep incrementing.

PHP Code:
$foo 0;
$foo++; 
This only increments it by 1 and then stops, and never increments again, now I might just have to make an existing counter or something to increment but this is for counting how many views are from a certain id in a database. Help, do I make this an Array, and keep adding onto the array by counting then adding that into it? :S
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-13-2008, 11:33 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Im not sure what you are trying to do, if you want to incriment a variable by more then one
PHP Code:
$var += 10
__________________

Village Idiot is offline  
Reply With Quote
Old 02-13-2008, 11:35 PM   #3 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default

can you do some kind of select

PHP Code:
$query mysql_query("SELECT * FROM example WHERE id = '$id'") or die(mysql_error());
$num mysql_num_rows($query); 
Or don't i understand what you actually mean by this question? maybe someone can explain?
__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
Old 02-13-2008, 11:41 PM   #4 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
Im not sure what you are trying to do, if you want to incriment a variable by more then one
PHP Code:
$var += 10
I've never used that operator.

Also, when a user clicks on say an id on a page, then it increments the views column by one, and is displayed on the page.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-13-2008, 11:54 PM   #5 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

I dont think there is a way to do that.
__________________

Village Idiot is offline  
Reply With Quote
Old 02-13-2008, 11:56 PM   #6 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
I dont think there is a way to do that.
There has to be a way. I've seen it before so..
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 12:07 AM   #7 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default

You can more likely do it using Ajax seems simply enough
__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
Old 02-14-2008, 12:55 AM   #8 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

I'm not entirely sure what you are trying to do, but in your original code, the reason it only increments it to 1 is because you are resetting the variable to 0 before you increment it.

I'm guessing that you want to do something like vBulletins thread views counter. The general idea is to get the number of views (ie, from a database), increment it by one, then store the new value back in the database.

If you wanted to update the page instantly, then use Ajax as Rendair suggested after you have read/write the values to the database.

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 02-14-2008, 03:06 AM   #9 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

What are you attempting to do? Reading your post again, it really doesnt make any sense.
__________________

Village Idiot is offline  
Reply With Quote
Old 02-14-2008, 03:09 AM   #10 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

I'm trying to increment every time there is a new view, a view is when someone goes onto a special page, and then it inserts the view into the mysql, and shows it on the front page. This is what I want for my image uploading script.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 03:49 AM   #11 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

Code:
UPDATE table
SET view_count= view_count+1
WHERE pageID= 1;
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
The Following User Says Thank You to SOCK For This Useful Post:
Orc (02-14-2008)
Old 02-14-2008, 04:06 AM   #12 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Quote:
Originally Posted by Orc View Post
I've never used that operator.

Also, when a user clicks on say an id on a page, then it increments the views column by one, and is displayed on the page.
It's not really a single operator, but rather a mixture of 2. PHP has a lot of them. It allows you to omit repeating the variable again. Otherwise it'd be like:

php Code:
$i = $i + 1;

So instead we use the following:

php Code:
$i /= $i;
$i += $i;
$i -= $i;
$i *= $i;
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-14-2008, 06:44 AM   #13 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by SOCK View Post
Code:
UPDATE table
SET view_count= view_count+1
WHERE pageID= 1;
You just solved my problem, but it increments by 2 every time I view a page.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 09:33 AM   #14 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

PHP Code:
$postQuery mysql_query('SELECT * FROM post WHERE id = "'.$_GET['id'].'"');
$postFetch mysql_fetch_array($postQuery);

$newViews $postFetch['viewcount'] + 1;

mysql_query('UPDATE post SET viewcount = "'.$newViews.'" WHERE id = "'.$_GET['id'].'"'); 
Finito.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
The Following User Says Thank You to ReSpawN For This Useful Post:
Orc (02-14-2008)
Old 02-14-2008, 10:30 AM   #15 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default

You can make it update the page instantly without having to refresh using something like this. You create 2 pages on with that script ReSpawn said or whatever and then the main page where you have some kind of onClick or something.

PHP Code:
<script type="text/javascript">
//<![CDATA[
var request false;

if(
window.XMLHttpRequest){
  
request = new XMLHttpRequest();
}else if(
window.ActiveXObject){
  
request = new ActiveXObject("Microsoft.XMLHTTP");
}

function 
getData(source){
  if(
request){

    var 
sourceId document.getElementById("hiddenFieldId").value;
    var 
newsource source "?id=" sourceId;
    
request.open("GET",newsource);
    
request.onreadystatechange = function(){
      
         if(
request.readyState 4){
              
document.getElementById("totalviews").innerHTML "Updating....";
         }
         else if(
request.readyState==4){
             
document.getElementById("totalviews").innerHTML request.responseText;
          }
          
    }
    
request.send(null);
  }
}

//]]>
</script> 
To use the script you can use something like

PHP Code:

<a href="#" onClick="getSource('process_views.php');"><div id="totalviews"4 Views </div></a
Or something along that line anyway.

This example has a use of a hidden field containing the id then you can use the MySQL on a new page.

PHP Code:
$postQuery mysql_query('SELECT * FROM post WHERE id = "'.$_GET['id'].'"');
$postFetch mysql_fetch_array($postQuery);

$newViews $postFetch['viewcount'] + 1;

mysql_query('UPDATE post SET viewcount = "'.$newViews.'" WHERE id = "'.$_GET['id'].'"'); 

echo 
$numViews// echo the new number of views to be displayed 
__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
The Following User Says Thank You to Rendair For This Useful Post:
Orc (02-14-2008)
Old 02-14-2008, 10:47 AM   #16 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Yeah, then you're using the AJAX framework. There are a lot of plugins for it if you're into it. Check out mootools.net Orc. :)
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
The Following User Says Thank You to ReSpawN For This Useful Post:
Orc (02-14-2008)
Old 02-14-2008, 10:49 AM   #17 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

It keeps saying on Gmail, that Village Idiot replied to this thread. :/
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 01:23 PM   #18 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

What do you mean? If you mean it gets the same ID over and over, you should make the $_GET['post'] or what ever dynamic.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 02-14-2008, 10:59 PM   #19 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by ReSpawN View Post
What do you mean? If you mean it gets the same ID over and over, you should make the $_GET['post'] or what ever dynamic.
Eh? No I ment that Gmail is screwed up, it keeps showing that Village Idiot has replied to this thread, but it's only someone else. :/
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 11:41 PM   #20 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Orc, if you want us to help you, you need to help us. What are you trying to do? We dont understand what you have previously said. If we know what you are trying to accomplish we could probably tell you how to do it.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:26 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design