lpxxfaintxx Posted April 8, 2006 Share Posted April 8, 2006 [code]$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";$result2=mysql_query($sql2);$rows2=mysql_fetch_array($result2);$views = $rows2['profileviews'];$arr = explode(",", $views);[/code]I thought it'd work but it just shows up as 1. What am I doing wrong?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/ Share on other sites More sharing options...
alpine Posted April 8, 2006 Share Posted April 8, 2006 [code] $number=count($arr);[/code]gives in your case the number of elements exploded by [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--],[!--colorc--][/span][!--/colorc--] Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-25099 Share on other sites More sharing options...
lpxxfaintxx Posted April 8, 2006 Author Share Posted April 8, 2006 Nope, still 1. Could it be the MySQL query? Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-25107 Share on other sites More sharing options...
kenrbnsn Posted April 9, 2006 Share Posted April 9, 2006 What does your data look like? What do you expect to be in the array element $rows2['profileviews']?Ken Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-25151 Share on other sites More sharing options...
lpxxfaintxx Posted April 9, 2006 Author Share Posted April 9, 2006 I expect it to look like Anounymous, user1, myname, lpxxfaintxx, tommy, etc. Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-25325 Share on other sites More sharing options...
lpxxfaintxx Posted April 10, 2006 Author Share Posted April 10, 2006 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-25487 Share on other sites More sharing options...
kenrbnsn Posted April 10, 2006 Share Posted April 10, 2006 Put in some debugging code to dump the $rows2 array after the fetch. I would also use the mysql_fetch_assoc() function instead of the mysql_fetch_array() function.Sample debug code:[code]<?php$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";$result2=mysql_query($sql2);$rows2=mysql_fetch_assoc($result2);echo '<pre>' . print_r($rows2,true) . '</pre>'; // debug code?>[/code]If this doesn't show what you expect, go back to the code that stored the information in the database and see if there is an error there.Please post what it shows.Ken Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-25502 Share on other sites More sharing options...
lpxxfaintxx Posted April 10, 2006 Author Share Posted April 10, 2006 I did what you wrote, I think... but it's doing something odd.[code]<?php $owner = $_GET['id'];require_once "db.php";$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";$result2=mysql_query($sql2);$rows2=mysql_fetch_assoc($result2);echo '<pre>' . print_r($rows2,true) . '</pre>'; // debug code$views = $rows2['profileviews'];$arr = explode(",", $views);$number=count($arr);?>This profile is hosted by <a href="http://aimmultimedia.com">AIM Multimedia.com</a> <br><?php echo $number; ?><hr>[/code]If I view the profileheader.php alone, it comes out as "1" [a href=\"http://aimmultimedia.com/profileheader.php\" target=\"_blank\"]http://aimmultimedia.com/profileheader.php[/a] but if I do an 'include' it shows the whole array, but still a 1. (Still a problem) [a href=\"http://aimmultimedia.com/viewprofile.php?id=lpxxfaintxx\" target=\"_blank\"]http://aimmultimedia.com/viewprofile.php?id=lpxxfaintxx[/a]Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-25602 Share on other sites More sharing options...
lpxxfaintxx Posted April 11, 2006 Author Share Posted April 11, 2006 Ok, now I tried this:[code]<?php $owner = $_GET['id'];require_once "db.php";$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";$result2=mysql_query($sql2);$rows2=mysql_fetch_assoc($result2);echo '<pre>' . print_r($rows2,true) . '</pre>'; // debug code$views = $rows2['profileviews'];$arr = explode(",", $views);$number=count($arr);?>This profile is hosted by <a href="http://aimmultimedia.com">AIM Multimedia.com</a> <br><?php echo '<pre> ' . print_r($rows2,true) . '</pre>'; ?><hr>[/code]but it comes out as blank. [a href=\"http://aimmultimedia.com/profileheader.php\" target=\"_blank\"]http://aimmultimedia.com/profileheader.php[/a] Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-25803 Share on other sites More sharing options...
lpxxfaintxx Posted April 12, 2006 Author Share Posted April 12, 2006 I've tried everything I can, but still no. Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-26164 Share on other sites More sharing options...
shocker-z Posted April 12, 2006 Share Posted April 12, 2006 what about?$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";$result2=mysql_query($sql2);$rows2=mysql_fetch_array($result2);$views = $rows2['profileviews'];$arr = explode(",", $views);$=0;foreach($arr as $count) {$i++;}echo $i;You tryed that? Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-26174 Share on other sites More sharing options...
lpxxfaintxx Posted April 12, 2006 Author Share Posted April 12, 2006 What should I do for the "$=0;" part of your script?edit: I tried the script without it, and again its just "1". This is driving me mad! Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-26320 Share on other sites More sharing options...
shocker-z Posted April 13, 2006 Share Posted April 13, 2006 Sorry should have been (typo)[code]$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";$result2=mysql_query($sql2);$rows2=mysql_fetch_array($result2);$views = $rows2['profileviews'];$arr = explode(",", $views);$i=0;foreach($arr as $count) {$i++;}echo $i;[/code]If thats not doin it then try [code]$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";$result2=mysql_query($sql2);$rows2=mysql_fetch_array($result2);$views = $rows2['profileviews'];echo('before explode value is: '.$views.'<Br>')$arr = explode(',', $views);$i=0;foreach($arr as $count) {$i++;echo('Comma: '.$i.' Value:'.$count.'<Br>');}[/code]This will help you by seeing origonal data, data being counted and so on.. Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-26515 Share on other sites More sharing options...
BladeMetal Posted April 13, 2006 Share Posted April 13, 2006 [!--quoteo(post=364332:date=Apr 13 2006, 07:01 PM:name=shocker-z)--][div class=\'quotetop\']QUOTE(shocker-z @ Apr 13 2006, 07:01 PM) [snapback]364332[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";$result2=mysql_query($sql2);$rows2=mysql_fetch_array($result2);$views = $rows2['profileviews'];echo('before explode value is: '.$views.'<Br>')$arr = explode(',', $views);$i=0;foreach($arr as $count) {$i++;echo('Comma: '.$i.' Value:'.$count.'<Br>');}[/code]This will help you by seeing origonal data, data being counted and so on..[/quote]I think mysql_fetch_array() should read mysql_fetch_assoc() if I'm not mistaken. Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-26525 Share on other sites More sharing options...
lpxxfaintxx Posted April 13, 2006 Author Share Posted April 13, 2006 Still "1". Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-26666 Share on other sites More sharing options...
kenrbnsn Posted April 13, 2006 Share Posted April 13, 2006 I think the problem is occuring in the script where you enter the data into the database, not in the script that looks at it.Let's start again...Please post the script that loads the data, including any forms that might be involved, then tell us how you want the data to be displayed.Ken Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-26704 Share on other sites More sharing options...
lpxxfaintxx Posted April 13, 2006 Author Share Posted April 13, 2006 Ok, the table is set up like this:CREATE TABLE `fusion_users` ( `user_id` smallint(5) unsigned NOT NULL auto_increment, `user_name` varchar(30) NOT NULL default '', `user_password` varchar(32) NOT NULL default '', `user_email` varchar(100) NOT NULL default '', `user_hide_email` tinyint(1) unsigned NOT NULL default '1', `user_location` varchar(50) NOT NULL default '', `user_birthdate` date NOT NULL default '0000-00-00', `user_aim` varchar(16) NOT NULL default '', `user_icq` varchar(15) NOT NULL default '', `user_msn` varchar(100) NOT NULL default '', `user_yahoo` varchar(100) NOT NULL default '', `user_web` varchar(200) NOT NULL default '', `user_theme` varchar(100) NOT NULL default 'Default', `user_offset` char(3) NOT NULL default '0', `user_avatar` varchar(100) NOT NULL default '', `user_sig` text NOT NULL, `user_posts` smallint(5) unsigned NOT NULL default '0', `user_joined` int(10) unsigned NOT NULL default '0', `user_lastvisit` int(10) unsigned NOT NULL default '0', `user_ip` varchar(20) NOT NULL default '0.0.0.0', `user_rights` text NOT NULL, `user_groups` text NOT NULL, `user_level` tinyint(3) unsigned NOT NULL default '101', `user_status` tinyint(1) unsigned NOT NULL default '0', [b] `profilehits` text NOT NULL, [/b] `lastview` varchar(20) NOT NULL default '', PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;This is a sample export of what a row might look like: INSERT INTO `fusion_users` VALUES (1, 'lpxxfaintxx', 'b572a1b0e48edb7405ab55feb2673', 'lpxxfaintxx@yahoo.com', 1, '', '0000-00-00', '', '', '', '', '', 'Default', '0', '', '', 2, 1143371157, 1144947993, '71.247.236.84', 'A.AC.AD.B.C.CP.DB.DC.D.FQ.F.IM.I.IP.M.N.NC.P.PH.PI.PO.S.SL.S1.S2.S3.S4.S5.S6.S7.SU.UG.U.W.WC', '.1', 103, 0, '[b]0lil alx9d1, BagFullOfRic, YOURMOM, fdndfnfd , fdndfnfd , fdndfnfd, fdndfnfd, fdndfnfd, fdndfnfd, sleeperpick10, BagFullOfRice, BagFullOfRice74, iix3JAD0REuU, iix3JAD0REuU, sinwillsin, sportzr4me18, sleeperpick10, BaSkEtBaLLQT8674, xpjisuuus, BagFullOfShyt, %n, %n, BagFullOfRice, Patelk0014, Patelk0014, BagFullOfRice, BagFullOfRice, , Patelk0014, flirtyazngrl09, bigshot9214, bigshot9214, bigshot9214, mnkmnkz16, bleausky22312, , , fashnFrEEk92, BagFullOfRice, BagFullOfRice, , xbsbdfbdbfdbfd, xbsbdfbdbfdbfd, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, , BagFullOfRice, %n, BagFullOfRice, %n, %n, , BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, %n, BagFullOfRice, BagFullOfRice, %n, BagFullOfRice, %n, BagFullOfRice, %n, BagFullOfShyt, BagFullOfShyt, BagFullOfShyt, rubberducky9314, rubberducky9314, rubberducky9314, %n, %n, BagFullOfRice, BagFullOfRice, BagFullOfRice, %n, Patelk0014, rubberducky9314, bigshot9214, bigshot9214, %n, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice[/b]', '');The bold is the whole "Profile Hits" part, so there should be at least 50 commas, not one.The whole page where I'm trying to echo out the commas is:[code]<?php$owner = $_GET['id'];require_once "db.php";$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";$result2=mysql_query($sql2);$rows2=mysql_fetch_assoc($result2);$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";$result2=mysql_query($sql2);$rows2=mysql_fetch_assoc($result2);$views = $rows2['profileviews'];$arr = explode(",", $views);#$=0;foreach($arr as $count) {$i++;}?>This profile is hosted by <a href="http://aimmultimedia.com">AIM Multimedia.com</a> <br>Become a BETA tester like me! <a href="http://aimmultimedia.com/application.php">Sign up here.</a><br><?php echo 'The profile has been viewed '.$i.' times.'; ?><hr>[/code]This is where the profilehits is getting updated and added<?phprequire_once "db.php";require_once "profileheader.php";$owner = $_GET['id'];[b]$visitor = $_GET['sn'];[/b]$status = 'Public'; [b]$idq = mysql_query("SELECT `profilehits` FROM `fusion_users` WHERE `user_name` = '$owner'"); $ida = mysql_fetch_assoc($idq); $newid = $ida['profilehits'] . ', '.$visitor;$sql = "UPDATE fusion_users SET profilehits='$newid' WHERE user_name = '$owner'"; $result = mysql_query($sql);[/b]$sql = "SELECT * FROM `registered_cat` WHERE `owner` = '$owner' AND `status` = '$status'";$result=mysql_query($sql);$num_rows = mysql_num_rows($result);echo 'There are '.$num_rows.' categories. Please choose one.<br><br>';while($row=mysql_fetch_array($result)){{$id = $row['id']; echo '<HTML><FONT FACE="Verdana" SIZE=4><A HREF="/viewprofilecat.php?id='.$id.'&sn=%n" TARGET="_self"><B>'.$row['cat_name'].'</B></A></FONT> <br>' . "Description : {$row['cat_description']} <br>" . "Total Images : {$row['id']} <br> <hr>";}}?>Sorry about the no code tags, I wanted to make the important parts more standing out.Again, thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-26746 Share on other sites More sharing options...
lpxxfaintxx Posted April 15, 2006 Author Share Posted April 15, 2006 [img src=\"http://www.phpfreaks.com/forums/style_images/1/folder_post_icons/icon9.gif\" border=\"0\" alt=\"IPB Image\" /] Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-27219 Share on other sites More sharing options...
kenrbnsn Posted April 15, 2006 Share Posted April 15, 2006 Found your problem.The field in the table is named "profilehits", the field you're trying to get is "profileviews". Change "profileviews" to "profilehits" and it will work.BTW, you don't need the "foreach" loop to count the number of commas. After you do the explode, just use the count() function on the array.[code]<?php$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";$result2=mysql_query($sql2);$rows2=mysql_fetch_assoc($result2);$views = $rows2['profileviews'];$arr = explode(",", $views);?>This profile is hosted by <a href="http://aimmultimedia.com">AIM Multimedia.com</a> <br>Become a BETA tester like me! <a href="http://aimmultimedia.com/application.php">Sign up here.</a><br><?php echo 'The profile has been viewed '. count($arr) .' times.'; ?>[/code]Another BTW --- if you change how you're storing the field "profilehits" from a CSV to a serialized array, it will make your scripting easier.In the scripts where the field gets updated:[code]<?php$idq = mysql_query("SELECT `profilehits` FROM `fusion_users` WHERE `user_name` = '$owner'");$ida = mysql_fetch_assoc($idq);$profilehits = ($ida['profilehits'] == '')?array():unserialize($ida['profilehits']);$profilehits[] = $visitor;$sql = "UPDATE fusion_users SET profilehits='" . serialize($profilehits) . "' WHERE user_name = '$owner'";$result = mysql_query($sql);?>[/code]Then in the "counting" script:[code]<?php$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";$result2=mysql_query($sql2);$rows2=mysql_fetch_assoc($result2);echo 'This profile is hosted by <a href="http://aimmultimedia.com">AIM Multimedia.com</a> <br>';echo 'Become a BETA tester like me! <a href="http://aimmultimedia.com/application.php">Sign up here.</a><br>';echo 'The profile has been viewed '. count(serialize($rows2['profilehits'])) .' times.'; ?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-27231 Share on other sites More sharing options...
lpxxfaintxx Posted April 15, 2006 Author Share Posted April 15, 2006 Ah, I feel so stupid now. Thanks a bunch. Quote Link to comment https://forums.phpfreaks.com/topic/6901-counting-commas/#findComment-27273 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.