Jump to content

String search in an array


sniperscope

Recommended Posts

Hello

I am facing a problem which i can not handle. I appreciate for any help.

 

My Database is:

CREATE TABLE IF NOT EXISTS `shops` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `options` text,
  `user_name` varchar(250) NOT NULL ,
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_name` (`user_name`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COMMENT='user data stored' AUTO_INCREMENT=1 ;

 

And some sample data as below:

INSERT INTO `users` (`id`, `options`, `user_name`) VALUES
(1, 'apple-orange-grape-bmw-toyota-fig-', 'user1'),
(4, 'apple-tomato-pc-notebook-yellow-', 'user2'),
(5, 'blue-green-orange-cdrom-', 'user3'),
(6, 'orange-yellow-blue-pink-bread-', 'user4');

 

How can i display how many apples or green or any item selected by user?

So far i tried in_array, array_count_values but seems no one is working.

 

Regards

 

 

Link to comment
Share on other sites

I solved.

Hope this solution help someone else.

$NEW_OPTION = array();
for($i=0; $i<count($OPTIONS); $i++)
{
$EXP = explode("-", $OPTIONS[$i]);
for($j=0; $j<count($EXP); $j++)
{
	$NEW_OPTION[] = $EXP[$j];
}
}
$DISPLAY_OPTIONS  = array(array_count_values($NEW_OPTION));

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.