View previous topic :: View next topic |
Author |
Message |
Goldmund -
Joined: 19 Feb 2005 Posts: 19 Location: Seattle, WA
|
Posted: Wed Mar 16, 2005 6:48 am Post subject: Creating a Forum question... |
|
|
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 |
|
|
Glitch2082 -
Joined: 02 Dec 2004 Posts: 194
|
Posted: Wed Mar 16, 2005 7:52 am Post subject: |
|
|
"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 |
|
|
Goldmund -
Joined: 19 Feb 2005 Posts: 19 Location: Seattle, WA
|
Posted: Thu Mar 17, 2005 5:06 am Post subject: |
|
|
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 |
|
|
Glitch2082 -
Joined: 02 Dec 2004 Posts: 194
|
Posted: Thu Mar 17, 2005 7:50 am Post subject: |
|
|
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 |
|
|
Goldmund -
Joined: 19 Feb 2005 Posts: 19 Location: Seattle, WA
|
Posted: Fri Mar 18, 2005 4:21 am Post subject: |
|
|
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 |
|
|
Glitch2082 -
Joined: 02 Dec 2004 Posts: 194
|
Posted: Fri Mar 18, 2005 5:31 am Post subject: |
|
|
lol np :P _________________ int main() {
cout << "Im Pro Apache";
cin.get();
} |
|
Back to top |
|
|
|