| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | |
| |
| | #2 (permalink) |
| Senior Member Join Date: Oct 2006 Location: NJ
Posts: 1,152
![]() ![]() ![]() | Replace this: $views_array = explode($views,','); With: $views_array = explode($views,','); $counterx = sizeof($counterx) - 1; $views_array[$counterx] = ""; See if that works; it should remove the last value of $views_array
__________________ Web Development |
| |
| | THREAD STARTER #3 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | Thanks for the suggestion. However, the comma is added to the beginning of the array each time. Sorry - I should have said. Also, should: $counterx = sizeof($counterx) - 1; be: $counterx = sizeof($views_array) - 1;
__________________ Encenta - Amazon Associates CMS |
| |
| | #4 (permalink) |
| Senior Member Join Date: Oct 2006 Location: NJ
Posts: 1,152
![]() ![]() ![]() | yeah...lol Okay then, replace this $views_array = explode($views,','); with: $views_array = explode($views,','); $views_array[0] = "";
__________________ Web Development |
| |
| | THREAD STARTER #5 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | Thanks again but it's still happening ![]() I've also got another problem. Rather than adding the new IP to the list, it's completely overwriting the list. So every time the page is refreshed, the list looks like: Code: ,XX.XXX.XXX.192
__________________ Encenta - Amazon Associates CMS |
| |
| | #6 (permalink) |
| Senior Member Join Date: Oct 2006 Location: NJ
Posts: 1,152
![]() ![]() ![]() | $ip = $_SERVER['REMOTE_ADDR']; $query = mysql_query("SELECT * FROM events WHERE id='$id'"); while ($row = mysql_fetch_array($query)) { $views = stripslashes($row['views']); } $views_array = array(); for ($count = 0; $count <= sizeof($views) - 1; $count++){ if ($views == "") { ????: NamePros.com http://www.namepros.com/showthread.php?t=270144 $views_array[$count] = $ip; $views_array[$count] = trim($views_array[$count],","); } else { $views_array = explode($views,','); if (!in_array($ip, $views_array)) { $views_array[$count] = $ip; $views_array[$count] = trim($views_array[$count],","); } } } $query = mysql_query("UPDATE bp_events SET views='".implode(",", $views_array)."' WHERE id = '$id'");
__________________ Web Development |
| |
| | THREAD STARTER #7 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | That's solved the comma problem but the list is still being overwritten
__________________ Encenta - Amazon Associates CMS |
| |
| | THREAD STARTER #9 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | Oh yeah, Whoops. Thanks for pointing that out. Problem with overwriting still remains though.
__________________ Encenta - Amazon Associates CMS |
| |
| | #10 (permalink) |
| Senior Member Join Date: Sep 2005
Posts: 1,112
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | miseria, your code is incorrect. check the loop, $views is overwritten every time, so when you are out of the loop, $views contains the last value. so the $views_array will surely contain only one value. unless that is what you want it to be. Also, why do you have 2 tables, views and bp_views? you read from the first and update int he second. |
| |
| | THREAD STARTER #11 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | You mean events and bp_events? it is all one table. I just modified it to make it less confusing but it actually did the opposite. It is correct in my script though. I am not sure where $views is being overwritten. (Sorry - it's been a bad day). EDIT: I think you mean where I am retrieving it from the database. 'views' is a list of IP addresses separated by a comma. This is why it is exploded later on.
__________________ Encenta - Amazon Associates CMS
Last edited by Encenta.com; 12-17-2006 at 09:52 AM.
|
| |
| | #12 (permalink) |
| Senior Member Join Date: Sep 2005
Posts: 1,112
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | So there is only one row in the table with the ips separated by comas. So technically you don't need that while loop at the start of the code. Secondly, I need to know what you exactly have. Execute this code and show me the output. PHP Code: |
| |
| | THREAD STARTER #13 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | http://beenplaces.com/2/test Had to make a few modifications - connecting to database, changing database name and changing '$id' to an actual number. Thanks
__________________ Encenta - Amazon Associates CMS |
| |