 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
02-13-2008, 10:43 PM
|
#1 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
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
|
|
|
|
02-13-2008, 11:33 PM
|
#2 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Im not sure what you are trying to do, if you want to incriment a variable by more then one
|
|
|
|
02-13-2008, 11:41 PM
|
#3 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Village Idiot
Im not sure what you are trying to do, if you want to incriment a variable by more then one
|
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
|
|
|
|
02-14-2008, 04:06 AM
|
#4 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
Quote:
Originally Posted by Orc
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:
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.
|
|
|
02-13-2008, 11:35 PM
|
#5 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
|
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?
|
|
|
02-13-2008, 11:54 PM
|
#6 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
I dont think there is a way to do that.
|
|
|
|
02-13-2008, 11:56 PM
|
#7 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Village Idiot
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
|
|
|
|
02-14-2008, 12:07 AM
|
#8 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
|
You can more likely do it using Ajax seems simply enough
|
|
|
02-14-2008, 12:55 AM
|
#9 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
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
|
|
|
02-14-2008, 03:06 AM
|
#10 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
What are you attempting to do? Reading your post again, it really doesnt make any sense.
|
|
|
|
02-14-2008, 03:09 AM
|
#11 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
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
|
|
|
|
02-14-2008, 03:49 AM
|
#12 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Posts: 154
Thanks: 31
|
Code:
UPDATE table
SET view_count= view_count+1
WHERE pageID= 1;
__________________
I reject your reality, and substitute my own.
|
|
|
|
|
The Following User Says Thank You to SOCK For This Useful Post:
|
|
02-14-2008, 06:44 AM
|
#13 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by SOCK
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
|
|
|
|
02-14-2008, 09:33 AM
|
#14 (permalink)
|
|
The Frequenter
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
|
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"
|
|
|
|
The Following User Says Thank You to ReSpawN For This Useful Post:
|
|
02-14-2008, 10:30 AM
|
#15 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
|
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
|
|
|
|
The Following User Says Thank You to Rendair For This Useful Post:
|
|
02-14-2008, 10:47 AM
|
#16 (permalink)
|
|
The Frequenter
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
|
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"
|
|
|
|
The Following User Says Thank You to ReSpawN For This Useful Post:
|
|
02-14-2008, 10:49 AM
|
#17 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
It keeps saying on Gmail, that Village Idiot replied to this thread. :/
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
02-14-2008, 01:23 PM
|
#18 (permalink)
|
|
The Frequenter
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
|
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"
|
|
|
02-14-2008, 10:59 PM
|
#19 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by ReSpawN
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
|
|
|
|
02-14-2008, 11:41 PM
|
#20 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
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.
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|