djfox Posted January 10, 2008 Author Share Posted January 10, 2008 What are the columns in your database? Does it contain the user's name or anything that you can use to get the particular user's inventory? I`ll just post the code: <?php if(!$offset) $offset=0; $recent = 0; $res = mysql_query("SELECT id,name FROM clothing ORDER BY name ASC")or die( mysql_error() ); while( $c = mysql_fetch_row($res) ){ if( $recent >= $offset && $recent < ($offset + 200000000 )){ $res2 = mysql_query("SELECT COUNT(*) FROM clot_sell WHERE item='$c[0]'"); $count1 = mysql_fetch_row($res2); mysql_free_result($res2); $res3 = mysql_query("SELECT COUNT(DISTINCT bought) FROM userdata WHERE bought='$c[0],'"); $count2 = mysql_fetch_row($res3); mysql_free_result($res3); $total = $count1[0] + $count2[0] ; echo "$c[1] -> <b>$total</b><br>"; } } $res4 = mysql_query("SELECT COUNT(*) FROM clot_sell"); $count3 = mysql_fetch_row($res4); mysql_free_result($res4); $res5 = mysql_query("SELECT COUNT(*) FROM clothing"); $count4 = mysql_fetch_row($res5); mysql_free_result($res5); echo "<p>Total for Sale: <b>$count3[0]</b>"; echo "<br>Total of types available: <b>$count4[0]</b><p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/85437-count-number-of-items-in-a-field/page/2/#findComment-436011 Share on other sites More sharing options...
Ken2k7 Posted January 10, 2008 Share Posted January 10, 2008 You can use the code The Little Guy posted, which is based on thorpe's idea. I'm unsure how you want to do this. Do you want to get 1 person's data or all? Something like this? <?php $res3 = mysql_query("SELECT bought FROM userdata"); if ($res || (mysql_num_rows($res3) > 0)){ echo array_count_values(explode(",",$res['bought'])); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85437-count-number-of-items-in-a-field/page/2/#findComment-436020 Share on other sites More sharing options...
djfox Posted January 10, 2008 Author Share Posted January 10, 2008 You can use the code The Little Guy posted, which is based on thorpe's idea. I'm unsure how you want to do this. Do you want to get 1 person's data or all? Something like this? <?php $res3 = mysql_query("SELECT bought FROM userdata"); if ($res || (mysql_num_rows($res3) > 0)){ echo array_count_values(explode(",",$res['bought'])); } ?> Yes, I wanted to count up all. I basically just wanted to see how many copies of an item was floating around. I posted your code in but that seems to have made no effect. Quote Link to comment https://forums.phpfreaks.com/topic/85437-count-number-of-items-in-a-field/page/2/#findComment-436024 Share on other sites More sharing options...
Ken2k7 Posted January 10, 2008 Share Posted January 10, 2008 Well if you know the item ID number, then you can do this: <?php $res3 = mysql_query("SELECT bought FROM userdata"); if ($res || (mysql_num_rows($res3) > 0)){ $arr = array_count_values(explode(",",$res['bought'])); // in this line, just say $arr[id] where id is the number you're looking for // } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85437-count-number-of-items-in-a-field/page/2/#findComment-436032 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.