Creating a Forum question...

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
Goldmund
-


Joined: 19 Feb 2005
Posts: 19
Location: Seattle, WA

PostPosted: Wed Mar 16, 2005 6:48 am    Post subject: Creating a Forum question... Reply with quote

I am working on creating a forum and I was wondering if anybody could help me with a simple problem...

I have a page that shows the different topics that users post and a page that views the topic and replies to that topic. My problem is that I can't get the 'views' value to increment when a user clicks on a topic link.

-Thanks
_________________
You learn something new every day.
Back to top View user's profile Send private message
Glitch2082
-


Joined: 02 Dec 2004
Posts: 194

PostPosted: Wed Mar 16, 2005 7:52 am    Post subject: Reply with quote

"views" shouldn't be auto_increment. It should be update with the update syntax as such, on, "view_topic.php", query....

UPDATE topics SET viewed_times=viewed_times+1 WHERE topic_id='id'
_________________
int main() {
cout << "Im Pro Apache";
cin.get();
}
Back to top View user's profile Send private message Send e-mail
Goldmund
-


Joined: 19 Feb 2005
Posts: 19
Location: Seattle, WA

PostPosted: Thu Mar 17, 2005 5:06 am    Post subject: Reply with quote

Have done, but I get the error:

--------------------------------------------------------------------------------------
Could not retrieve the data because: . The query was UPDATE post SET views=1 WHERE forum_id='177'.
--------------------------------------------------------------------------------------

I know the reason for this error is that the value for 'views' already equals 1, but how do I to equal 2 next time I view this post, then 3 and so on? Here is the code I used:

--------------------------------------------------------------------------------------
$views = ($_POST['views'] + 1);

$query = "UPDATE post SET views=$views WHERE forum_id='{$_GET['id']}'";
$result = mysql_query ($query);
if (mysql_affected_rows() == 1) {
print '<p>The forum has been updated.</p>';
} else {
die ('<p>Could not retrieve the data because: <b>' . mysql_error() . "</b>.
The query was $query.</p>");
}
--------------------------------------------------------------------------------------

I'm not sure what to do about this. Any help would be greatful. Thanks!
_________________
You learn something new every day.
Back to top View user's profile Send private message
Glitch2082
-


Joined: 02 Dec 2004
Posts: 194

PostPosted: Thu Mar 17, 2005 7:50 am    Post subject: Reply with quote

Instead of putting views in a string with a post, it should just be ...
$query = "UPDATE post SET views=views+1 WHERE forum_id='{$_GET['id']}'";
_________________
int main() {
cout << "Im Pro Apache";
cin.get();
}
Back to top View user's profile Send private message Send e-mail
Goldmund
-


Joined: 19 Feb 2005
Posts: 19
Location: Seattle, WA

PostPosted: Fri Mar 18, 2005 4:21 am    Post subject: Reply with quote

Great! It worked! And sorry, that's what you tried to tell me the first time.
_________________
You learn something new every day.
Back to top View user's profile Send private message
Glitch2082
-


Joined: 02 Dec 2004
Posts: 194

PostPosted: Fri Mar 18, 2005 5:31 am    Post subject: Reply with quote

lol np :P
_________________
int main() {
cout << "Im Pro Apache";
cin.get();
}
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group