Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-13-2010, 02:05 PM   PM User | #1
great_friend
New to the CF scene

 
Join Date: Dec 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
great_friend is an unknown quantity at this point
How can I remove values from array

Hi Guys,

I have an event calendar which values are coming from array
I want to remove all values except those which dates are available in mysql database

below are the code
<?php
$days = array(
1=>array('/weblog/archive/2004/Jan/02','linked-day'),
2=>array('/weblog/archive/2004/Jan/03','linked-day'),
3=>array('/weblog/archive/2004/Jan/08','linked-day'),
4=>array('/weblog/archive/2004/Jan/22','linked-day'),
5=>array('/weblog/archive/2004/Jan/22','linked-day'),
6=>array('/weblog/archive/2004/Jan/22','linked-day'),
7=>array('/weblog/archive/2004/Jan/22','linked-day'),
8=>array('/weblog/archive/2004/Jan/22','linked-day'),
9=>array('/weblog/archive/2004/Jan/22','linked-day'),
10=>array('/weblog/archive/2004/Jan/22','linked-day'),
11=>array('/weblog/archive/2004/Jan/22','linked-day'),
12=>array('/weblog/archive/2004/Jan/22','linked-day'),
13=>array('/weblog/archive/2004/Jan/22','linked-day'),
14=>array('/weblog/archive/2004/Jan/22','linked-day'),
15=>array('/weblog/archive/2004/Jan/22','linked-day'),
16=>array('/weblog/archive/2004/Jan/22','linked-day'),
17=>array('/weblog/archive/2004/Jan/22','linked-day'),
18=>array('/weblog/archive/2004/Jan/22','linked-day'),
19=>array('/weblog/archive/2004/Jan/22','linked-day'),
20=>array('/weblog/archive/2004/Jan/22','linked-day'),
21=>array('/weblog/archive/2004/Jan/22','linked-day'),
22=>array('/weblog/archive/2004/Jan/22','linked-day'),
23=>array('/weblog/archive/2004/Jan/22','linked-day'),
24=>array('/weblog/archive/2004/Jan/22','linked-day'),
25=>array('/weblog/archive/2004/Jan/22','linked-day'),
26=>array('/weblog/archive/2004/Jan/22','linked-day'),
27=>array('/weblog/archive/2004/Jan/22','linked-day'),
28=>array('/weblog/archive/2004/Jan/22','linked-day'),
29=>array('/weblog/archive/2004/Jan/22','linked-day'),
30=>array('/weblog/archive/2004/Jan/22','linked-day'),
31=>array('/weblog/archive/2004/Jan/22','linked-day'),
);

?>

I want to remove all the above values except which dates are available in mysql table fields

here is mysql table and few sample data

es_events CREATE TABLE `es_events` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`dt` varchar(255) DEFAULT NULL,
`event` varchar(255) DEFAULT NULL,
`detail` text,
`active` enum('yes','no') DEFAULT NULL,
PRIMARY KEY (`id`)
)

insert into `es_events`(`id`,`dt`,`event`,`detail`,`active`) values (2,'22','yhh1','dd xcv&nbsp; <strong>Lorem Ipsum</strong> is simply dummy text of the printing and \r\ntypesetting industry. Lorem Ipsum has been the industry\'s standard dummy\r\n text ever since the 1500s, when an unknown printer took a galley of \r\ntype and scrambled it to make a type specimen book. It has survived not \r\nonly five centuries, but also the leap into electronic typesetting, \r\nremaining essentially unchanged. It was popularised in the 1960s with \r\nthe release of Letraset sheets containing Lorem Ipsum passages, and more\r\n recently with desktop publishing software like Aldus PageMaker \r\nincluding versions of Lorem Ipsum. <br>','yes'),(3,'2',NULL,NULL,'yes'),(4,'5',NULL,NULL,'yes'),(5,'10',NULL,NULL,'yes'),(6,'11',NULL,N ULL,'yes'),(7,'13',NULL,NULL,'yes'),(8,'14.',NULL,NULL,'yes');(6,'2010-12-11',NULL,NULL,'yes'),(7,'2010-12-13',NULL,NULL,'yes'),(8,'2010-12-14.',NULL,NULL,'yes');

please help me guys and let me know how can i resolved this problem

Thank you soo much
great_friend is offline   Reply With Quote
Old 12-13-2010, 03:58 PM   PM User | #2
poyzn
Regular Coder

 
poyzn's Avatar
 
Join Date: Nov 2010
Posts: 265
Thanks: 2
Thanked 61 Times in 61 Posts
poyzn is on a distinguished road
PHP Code:
$mysql_dates = array(); // array of dates from the db - just select dates into array
$my_dates = array(); // you $days array
foreach($my_dates as $key => $val)
{
  if(!
in_array($key$mysql_dates))
  {
     unset(
$my_dates[$key]);
  }

__________________
Ushousebuilders.com
poyzn is offline   Reply With Quote
Old 12-13-2010, 04:01 PM   PM User | #3
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
Originally Posted by poyzn View Post
PHP Code:

foreach($my_dates as $key => $val)
{
  if(!
in_array($key$mysql_dates))
  {
     unset(
$my_dates[$key]);
  }

The above part can be replaced by array_diff()
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 12-13-2010, 06:46 PM   PM User | #4
poyzn
Regular Coder

 
poyzn's Avatar
 
Join Date: Nov 2010
Posts: 265
Thanks: 2
Thanked 61 Times in 61 Posts
poyzn is on a distinguished road
Quote:
Originally Posted by abduraooft View Post
The above part can be replaced by array_diff()
you are likely to have meant array_intersect()
__________________
Ushousebuilders.com
poyzn is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:26 PM.


Advertisement
Log in to turn off these ads.