Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-30-2009, 08:53 AM
  #1
rorypickering
Novice (Level 1)
 
Join Date: Jul 2009
Posts: 8
iTrader: (0)
rorypickering is an unknown quantity at this point
creating an item inventory

can i have suggestions on best way to this

how can i determine what items a user has from the inventory array?

e.g. '4,4,5,4,4,4';

i know that i habve to explode the string at ',' but how what code do i need to write so it says,

item number 4 , you have 5.
item number 5, you have 1.

so i need it to count each number and do a mysql query to fetch the info about that item and say how many this user has???

cheers

Last edited by rorypickering : 10-30-2009 at 09:16 AM.
rorypickering is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-04-2009, 11:40 AM
  #2
Vege
Super Deity (Level 18)
 
Join Date: Sep 2004
Location: Finland
Posts: 3,410
iTrader: (0)
Vege is just really niceVege is just really niceVege is just really niceVege is just really nice
PHP Code:
$str ='4,4,5,4,4,4';

$exp explode(",",$str);
//array to hold the numbers
$nums = array();
//loop trought the array
foreach($exp as $v)
{
   
//we insert the exp v as index and count how meny times it's been looped
   
if(!isset($nums[$v]))
    
$nums[$v]=0;
   else
   
$nums[$v]++;
}

foreach(
$nums as $k=>$v)
{
  echo 
$k."=".$v;

Something like that?
Vege is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 09:27 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.