I'm revisiting this as I'm working on another page that I want to use the same concept.
This page shows the output that I'm currently getting from my MSSQL server.
I have a table of venue information (name, address, etc...) that our events happen on. Separately, I have a table of the actual events that are scheduled (an event may happen multiple times in one day and/or over multiple days). I join those tables with a query (as seen below).
<?php
try {
$dbh = new PDO("sqlsrv:Server=localhost;Database=Sermons", "", "");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT TOP (100) PERCENT dbo.TblSermon.Day, dbo.TblSermon.Date, dbo.TblSermon.Time, dbo.TblSermon.Speaker, dbo.TblSermon.Series, dbo.TblSermon.Sarasota, dbo.TblSermon.NonFlc, dbo.TblJoinSermonLocation.MeetingName, dbo.TblLocation.Location, dbo.TblLocation.Pastors, dbo.TblLocation.Address, dbo.TblLocation.City, dbo.TblLocation.State, dbo.TblLocation.Zip, dbo.TblLocation.Country, dbo.TblLocation.Phone, dbo.TblLocation.Email, dbo.TblLocation.WebAddress
FROM dbo.TblLocation RIGHT OUTER JOIN dbo.TblJoinSermonLocation ON dbo.TblLocation.ID = dbo.TblJoinSermonLocation.Location RIGHT OUTER JOIN dbo.TblSermon ON dbo.TblJoinSermonLocation.Sermon = dbo.TblSermon.ID
WHERE (dbo.TblSermon.Date >= { fn NOW() })
ORDER BY dbo.TblSermon.Date, dbo.TblSermon.Time";
$stmt = $dbh->prepare($sql);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach ($stmt as $row) {
echo "<pre>";
print_r($row);
echo "</pre>";
}
unset($row);
$dbh = null;
}
catch(PDOException $e) {
echo $e->getMessage();
}
?>
So, as it loops through the query results, it creates an array for each record.
Array
(
[Day] => Tuesday
[Date] => 2012-10-30 00:00:00.000
[Time] => 07:00 PM
[Speaker] => Keith Moore
[Location] => The Ark Church
[Pastors] => Alan & Joy Clayton
[Address] => 450 Humble Tank Rd.
[City] => Conroe
[State] => TX
[Zip] => 77305.0
[Phone] => (936) 756-1988
[Email] => info#thearkchurch.com
[WebAddress] => http://www.thearkchurch.org
)
Array
(
[Day] => Wednesday
[Date] => 2012-10-31 00:00:00.000
[Time] => 07:00 PM
[Speaker] => Keith Moore
[Location] => The Ark Church
[Pastors] => Alan & Joy Clayton
[Address] => 450 Humble Tank Rd.
[City] => Conroe
[State] => TX
[Zip] => 77305.0
[Phone] => (936) 756-1988
[Email] => info#thearkchurch.com
[WebAddress] => http://www.thearkchurch.org
)
Array
(
[Day] => Tuesday
[Date] => 2012-11-06 00:00:00.000
[Time] => 07:00 PM
[Speaker] => Keith Moore
[Location] => Fellowship Of Faith Christian Center
[Pastors] => Michael & Joan Kalstrup
[Address] => 18999 Hwy. 59
[City] => Oakland
[State] => IA
[Zip] => 51560.0
[Phone] => (712) 482-3455
[Email] => ffcc#frontiernet.net
[WebAddress] => http://www.fellowshipoffaith.cc
)
Array
(
[Day] => Wednesday
[Date] => 2012-11-14 00:00:00.000
[Time] => 07:00 PM
[Speaker] => Keith Moore
[Location] => Faith Family Church
[Pastors] => Michael & Barbara Cameneti
[Address] => 8200 Freedom Ave NW
[City] => Canton
[State] => OH
[Zip] => 44720.0
[Phone] => (330) 492-0925
[Email] =>
[WebAddress] => http://www.myfaithfamily.com
)
What I'm wanting to do is combine those arrays, in some fashion, so that the venue information isn't repeated every time, but each date/time is show.
I tried typing it out in array style, but couldn't figure out the appropriate multi-dimensionality for it. I'm just pasting how I would like it to display, since that is how it will end up.
The Ark Church
Contact:
Alan & Joy Clayton
450 Humble Tank Rd.
Conroe, TX 77305
(936) 756-1988
info#thearkchurch.com
http://www.thearkchurch.org
Meetings:
Tuesday, 2012-10-30 07:00 PM
Wednesday, 2012-10-31 07:00 PM
Fellowship Of Faith Christian Center
Contact:
Michael & Joan Kalstrup
18999 Hwy. 59
Oakland, IA 51560
(712) 482-3455
ffcc#frontiernet.net
http://www.fellowshipoffaith.cc
Meetings:
Tuesday, 2012-11-06 07:00 PM
Faith Family Church
Contact:
Michael & Barbara Cameneti
8200 Freedom Ave NW
Canton, OH 44720
(330) 492-0925
http://www.myfaithfamily.com
Meetings:
Wednesday, 2012-11-14 07:00 PM
It doesn't necessarily have to end up like that, but it should give a good idea of what I'm looking for.
I don't necessarily have to create a new array. I just want to not show the same information over and over and over.
I was thinking that I could just do some form of compare, in foreach() that says something along the lines of "if Location is the same as previous Location", but I haven't figured out how to do it (is there a way to cache a previous variable with doing $location1 = [Location], $location2 = [Location], etc...?
One thing to note...
These examples don't have different speakers, but sometimes there are. I would like to be able to access the speaker, somehow. I assume that I would want it bound to the actual event.
JJ
One technique: if you have a loop like this:
while ($row = $query->fetch(PDO::FETCH_NUM) ) {
list($time,$place,$etc) = $row;
// display formatted data
}
try this instead:
$row = $query->fetch();
do {
list($time,$place,$etc) = $row;
$row = $query->fetch(PDO::FETCH_NUM);
if ($time != $row[0] && $place != $row[1] && $etc != $row[2]) {
// display formatted data
}
} while ($row);
I usually would approach a problem like this by creating a two-dimensinoal array, indexed by date then ID or in your case by ID then date.
Loop through events (the first dimension) and print out the contents of that event - while in there loop through the dates on that event and print those out as a list as in your example.
Related
I have weekly international events saved with day, hour, minute, somewhat like this:
Array
(
[0] => Array
(
[event] => Pear festival
[city] => London
[country] => UK
[local-day] => Saturday
[local-time] => 09:00
)
[1] => Array
(
[event] => Apple festival
[city] => New York
[country] => US
[local-day] => Saturday
[local-time] => 10:00
)
[2] => Array
(
[event] => Kiwi festival
[city] => Wellington
[country] => NZ
[local-day] => Saturday
[local-time] => 11:00
)
)
I'm trying to figure out a way to order these chronologically by UTC. I guess this is easy enough if I add the current local time zone to each event before the data is saved. However, countries have summer time and standard time. For example, New Zealand is currently on NZST, which is UTC+13, but after March they return to DST UTC+12.
Anyhow, as things currently stand (January 2021), these events would be ordered:
Array
(
[0] => Array
(
[event] => Kiwi festival
[city] => Wellington
[country] => NZ
[utc-day] => Friday
[utc-time] => 22:00
)
[1] => Array
(
[event] => Pear festival
[city] => London
[country] => UK
[utc-day] => Saturday
[utc-time] => 09:00
)
[2] => Array
(
[event] => Apple festival
[city] => New York
[country] => US
[utc-day] => Saturday
[utc-time] => 14:00
)
)
But after March, the NZ time would be an hour out, and the same for the other countries when they switch to summer time.
Any ideas how to solve this?
I would suggest to add a column in the events table which will store timestamp of your event in UTC no matter this the region event is happening in.
You can use PHP's default DateTime class or widely accepted libraries like Carbon to get the UTC timestamp from a date. You already have the countries and the time in the table. So when you save the event, generate its UTC timestamp and save. And for already existing events, you can do that in bulk once.
This way you can just order your events directly by the UTC timestamps column. This will also help you a lot in longer run if you want to get all events which will happen on a specific date and time, you can check that directly using the UTC timestamp column.
On a side note, this is also helpful in a way that you would have no date logic in your MySQL query other than the one to order results.
I am working with Symfony framework and I have a Controller whose job is to fetch the RSS feeds.
Once I have the fetched feeds in a set of array, I would like to remove those feeds whose date is greater than the date I provide.
So this is the array of object that I get when I fetch the feeds
Array
(
[0] => AppBundle\Entity\Rss Object
(
[id:AppBundle\Entity\Rss:private] =>
[feedItemTitle:AppBundle\Entity\Rss:private] => Project Manager, Investments Business Management - Prudential - Madison, NJ
[feedItemDescription:AppBundle\Entity\Rss:private] => Globally, PREI has offices in Munich, Frankfurt, London, Paris, Luxembourg, Singapore, Seoul, Tokyo, Sydney, and Mexico City....
From Prudential - 30 Jul 2015 20:00:31 GMT
- View all Madison jobs
[feedItemLink:AppBundle\Entity\Rss:private] => http://www.indeed.com/job/Project-Manager-at-Prudential-in-Madison,-NJ-27eedeae3104d1be
[feedItemPubDate:AppBundle\Entity\Rss:private] => DateTime Object
(
[date] => 2015-07-30 20:00:31.000000
[timezone_type] => 1
[timezone] => +00:00
)
)
[1] => AppBundle\Entity\Rss Object
(
[id:AppBundle\Entity\Rss:private] =>
[feedItemTitle:AppBundle\Entity\Rss:private] => Client Services Specialist - Prudential - Madison, NJ
[feedItemDescription:AppBundle\Entity\Rss:private] => Globally, PREI has offices in Munich, Frankfurt, London, Paris, Luxembourg, Singapore, Seoul, Tokyo, Sydney, and Mexico City....
From Prudential - 03 Aug 2015 19:59:34 GMT
- View all Madison jobs
[feedItemLink:AppBundle\Entity\Rss:private] => http://www.indeed.com/job/Client-Service-Specialist-at-Prudential-in-Madison,-NJ-51ad596876a01466
[feedItemPubDate:AppBundle\Entity\Rss:private] => DateTime Object
(
[date] => 2015-08-03 19:59:34.000000
[timezone_type] => 1
[timezone] => +00:00
)
)
[2] => AppBundle\Entity\Rss Object
(
[id:AppBundle\Entity\Rss:private] =>
[feedItemTitle:AppBundle\Entity\Rss:private] => Manager, Client Services - Prudential - Madison, NJ
[feedItemDescription:AppBundle\Entity\Rss:private] => Globally, PREI has offices in Munich, Frankfurt, London, Paris, Luxembourg, Singapore, Seoul, Tokyo, Sydney, and Mexico City....
From Prudential - 03 Aug 2015 19:59:32 GMT
- View all Madison jobs
[feedItemLink:AppBundle\Entity\Rss:private] => http://www.indeed.com/job/Manager-at-Prudential-in-Madison,-NJ-c0452d58384711e7
[feedItemPubDate:AppBundle\Entity\Rss:private] => DateTime Object
(
[date] => 2015-08-03 19:59:32.000000
[timezone_type] => 1
[timezone] => +00:00
)
)
[3] => AppBundle\Entity\Rss Object
(
[id:AppBundle\Entity\Rss:private] =>
[feedItemTitle:AppBundle\Entity\Rss:private] => Technical Sales Representative, Cell Culture Products - STEMCELL Technologies Inc - United States
[feedItemDescription:AppBundle\Entity\Rss:private] => We create novel, useful, standardized products of unfailing quality and deliver them to more than 70 countries via our many regional offices plus distribution...
From STEMCELL Technologies Inc - 01 Aug 2015 01:16:36 GMT
- View all jobs
[feedItemLink:AppBundle\Entity\Rss:private] => http://www.indeed.com/job/Technical-Sales-Representative-at-STEMCELL-Technologies-in-United-States-f4c10a0e10852686
[feedItemPubDate:AppBundle\Entity\Rss:private] => DateTime Object
(
[date] => 2015-08-01 01:16:36.000000
[timezone_type] => 1
[timezone] => +00:00
)
)
[4] => AppBundle\Entity\Rss Object
(
[id:AppBundle\Entity\Rss:private] =>
[feedItemTitle:AppBundle\Entity\Rss:private] => Technical Sales Representative, Cell Separation Products - STEMCELL Technologies Inc - United States
[feedItemDescription:AppBundle\Entity\Rss:private] => We create novel, useful, standardized products of unfailing quality and deliver them to more than 70 countries via our many regional offices plus distribution...
From STEMCELL Technologies Inc - 31 Jul 2015 01:13:35 GMT
- View all jobs
[feedItemLink:AppBundle\Entity\Rss:private] => http://www.indeed.com/job/Technical-Sales-Representative-at-STEMCELL-Technologies-in-United-States-b8c62120268afb55
[feedItemPubDate:AppBundle\Entity\Rss:private] => DateTime Object
(
[date] => 2015-07-31 01:13:35.000000
[timezone_type] => 1
[timezone] => +00:00
)
)
[5] => AppBundle\Entity\Rss Object
(
[id:AppBundle\Entity\Rss:private] =>
[feedItemTitle:AppBundle\Entity\Rss:private] => Accounting Intern - Code Corp - Draper, UT
[feedItemDescription:AppBundle\Entity\Rss:private] => Would love someone that is interested in International Accounting processes because this position will work with our China, Singapore & Europe office....
From Code Corp - 31 Jul 2015 21:13:43 GMT
- View all Draper jobs
[feedItemLink:AppBundle\Entity\Rss:private] => http://www.indeed.com/job/Accounting-Intern-at-Code-in-Draper,-UT-0e0aca45e988cc89
[feedItemPubDate:AppBundle\Entity\Rss:private] => DateTime Object
(
[date] => 2015-07-31 21:13:43.000000
[timezone_type] => 1
[timezone] => +00:00
)
)
)
As you will notice date in above array.
I am passing the above array and date (not the date from an array above but the $date that i would like to match the array date with to exclude the feed or not) in a parameter to a function below
public function isValid($feed, $date)
{
foreach ($feed as $item) {
if ($item->getfeedItemPubDate()->date < $date) {
echo $item->getfeedItemPubDate()->date;
echo "<br>";
}
}
}
I am able to get the list of feeds whose date from array are smaller than $date but what I am stuck at is how to remove those feeds from the array ? and then pass back the new set of array back to the controller.
You can remove array item by unset function. To know key of that item change a little foreach loop. As so, for example
public function isValid($feed, $date)
{
foreach ($feed as $key => $item)
if ($item->getfeedItemPubDate()->date < $date)
unset ($feed[$key]);
}
You can also try the array_filter function to which you provide a callback function, in your case something like
$feed = array_filter($feed, function($item) use($date) {
return ($item->getfeedItemPubDate()->date < $date);
});
where $date is a variable you set before
Try:
public function isValid($feed, $date)
{
foreach ($feed as $item) {
if (strtotime($item->getfeedItemPubDate()->date) < strtotime($date)) {
echo $item->getfeedItemPubDate()->date;
echo "<br>";
}
}
}
I have an array $dataStoreForTableImport set up in the following way.
$dataStoreForTableImport['title']
$dataStoreForTableImport['content']
$dataStoreForTableImport['date']
$dataStoreForTableImport['link']
$dataStoreForTableImport['username']
$dataStoreForTableImport['website']
It contains data as below
Array
(
[0] => Array
(
[title] => Quote from Tony Blair
[content] => ... from beating it I'm afraid." (Tony Blair, Sky News) He had every opportunity to put religion in its ...
[articledate] => 28/09/2013
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12890951
[Username] => Michael Dray
[website] => The Motley Fool
)
[1] => Array
(
[title] => Re: The Tony Blair Show
[content] => ... I am irritated that he got such an easy ride; Why? Because he is not to your political liking? He was a witness; he was not on trial and he spoke under oath. What did you expect Jay to ask him? I had dealings with a QC a few years ago. He was as ...
[articledate] => 28/05/2012
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12564154
[Username] => Michael Dray
[website] => The Motley Fool
)
[2] => Array
(
[title] => Re: The Tony Blair Show
[content] => ... If your doubts about Jay's competence/bias were shared I'm sure it would have been debated ad nauseam on Radio 4. Eh - are you serious? I'm a Radio 4 fan - but thats despite its hatred of all things right of centre, not becuase of. ...
[articledate] => 28/05/2012
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12564167
[Username] => Michael Dray
[website] => The Motley Fool
)
[3] => Array
(
[title] => Re: The Tony Blair Show
[content] => ... Maybe Tony should have brought Cherie with him - remember Rupert Murdoch and the reaction of Wendi Deng to the custard pie incident. IMHO Cherie is every bit as intimidating:-) Wendi Deng did not eject the pie flinger, she intervened when he acted. Use of an angled bat to deflect criticism from ...
[articledate] => 30/05/2012
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12565346
[Username] => Michael Dray
[website] => The Motley Fool
)
[4] => Array
(
[title] => Re: The Tony Blair Show
[content] => ... What did surprise me was the fact that he had his own personal bodyguards in the hearing with him. Although, given the level of security that allowed that protester to break into the hearing, maybe he had a point! Eh? He is clearly at risk of terror ...
[articledate] => 28/05/2012
[link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12564500
[Username] => Michael Dray
[website] => The Motley Fool
)
I want to be able to remove rows from this array that if the articleDate is before a given date.
I have tried everything but it does not seem to work. I am not even able to get it to sort correctly by date?
The date comes in the format - February 10, 2007
I have used
$sortDate = date('d/m/Y', strtotime($sortDate));
to format it to the format shown in the array above.
Can anyone please help?
Thanks
Mike
Do the filtering and sorting of rows in the database backend. This will improve the performance of you app. Use a WHERE clause for filtering by date and an ORDER BY clause for ordering by date in you SQL query.
I want to check a value in an array. If its not there it gets pushed to a new array. If the value is already there then its not added to the new value.
But with my code the checking of the value is not working.
Its still adding the array if the specific value is present.
I got this code:
foreach($user_movie_info['data'] as $movie) {
similar_text($movie_facebook_page['genre'], $movie['genre'], $percent);
if ($percent > 30) {
echo $movie_facebook_page['genre']. "" ."</br>";
echo $movie['genre']. "" ."</br>";
echo $percent. "" ."</br>";
echo "match! </br></br>";
// add all movie information to matched array, only if its not already present
if (!in_array($movie_facebook_page['name'], $matched_movies_array)) {
array_push($matched_movies_array, $movie_facebook_page);
}
} //foreach
If i print out the $matched_movies_array i got one array 2 times in it:
Array
(
[0] => Array
(
[about] => In theaters January 4th 2013 www.TexasChainsaw3D.com
[can_post] => 1
[description] => Lionsgate’s TEXAS CHAINSAW 3D continues the legendary story of the homicidal Sawyer family, picking up where Tobe Hooper’s 1974 horror classic left off in Newt, Texas, where for decades people went missing without a trace. The townspeople long suspected the Sawyer family, owners of a local barbeque pit, were somehow responsible. Their suspicions were finally confirmed one hot summer day when a young woman escaped the Sawyer house following the brutal murders of her four friends. Word around the small town quickly spread, and a vigilante mob of enraged locals surrounded the Sawyer stronghold, burning it to the ground and killing every last member of the family – or so they thought.
Decades later and hundreds of miles away from the original massacre, a young woman named Heather learns that she has inherited a Texas estate from a grandmother she never knew she had. After embarking on a road trip with friends to uncover her roots, she finds she is the sole owner of a lavish, isolated Victorian mansion. But her newfound wealth comes at a price as she stumbles upon a horror that awaits her in the mansion’s dank cellars…
With gruesome surprises in store for a whole new generation, TEXAS CHAINSAW 3D stars Alexandra Daddario, Dan Yeager, Tremaine ‘Trey Songz’ Neverson, Scott Eastwood, Tania Raymonde, Shaun Sipos, Keram Malicki-Sanchez, James MacDonald, Thom Barry, Paul Rae and Richard Riehle, along with special appearances from four beloved cast members from previous installments of the franchise: Gunnar Hansen (the original Leatherface), Marilyn Burns, John Dugan and Bill Moseley. The film is directed by John Luessenhop (TAKERS), from a screenplay by Adam Marcus & Debra Sullivan and Kirsten Elms, based on a story by Stephen Susco and Adam Marcus & Debra Sullivan and based on characters created by Kim Henkel and Tobe Hooper, and produced by Carl Mazzocone. Lionsgate presents a production and Main Line Pictures production.
[directed_by] => John Luessenhop
[genre] => Horror
[is_published] => 1
[produced_by] => Millennium Films
[release_date] => January 4th 2012
[screenplay_by] => Adam Marcus & Debra Sullivan and Kirsten Elms
[starring] => Alexandra Daddario, Dan Yeager, Tremaine ‘Trey Songz’ Neverson, Scott Eastwood, Tania Raymonde, Shaun Sipos, Keram Malicki-Sanchez, James MacDonald, Thom Barry, Paul Rae and Richard Riehle
[studio] => Lionsgate
[talking_about_count] => 62964
[username] => TexasChainsaw3D
[website] => www.texaschainsaw3d.com, twitter.com/lionsgatehorror, http://pinterest.com/lionsgatemovies/texas-chainsaw-3d, https://plus.google.com/u/0/+LionsgateMovies, http://instagr.am/p/Qpm0JMPtDr/
[were_here_count] => 0
[written_by] => based on a story by Stephen Susco and Adam Marcus & Debra Sullivan
[category] => Movie
[id] => 323192834416509
[name] => Texas Chainsaw 3D
[link] => http://www.facebook.com/TexasChainsaw3D
[likes] => 367992
[cover] => Array
(
[cover_id] => 4.14284428641E+14
[source] => http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash3/s720x720/530974_414284428640682_1806025466_n.png
[offset_y] => 0
)
)
[1] => Array
(
[about] => The official Facebook Page for The Shining | All work and no play makes Jack a dull boy.
[awards] => (1981) Saturn Award, Best Supporting Actor, Scatman Crothers
[can_post] => 1
[description] => Get The Shining at the WB Shop: http://bit.ly/shiningdvd
[directed_by] => Stanley Kubrick
[genre] => Horror, Suspense/Thriller
[is_published] => 1
[plot_outline] => All work and no play makes Academy Award-winner Jack Nicholson ("As Good As It Gets," "Batman"), the caretaker of an isolated resort, go way off the deep end, terrorizing his young son and wife Shelley Duvall ("Roxanne"). Master filmmaker Stanley Kubrick's ("Full Metal Jacket," "2001: A Space Odyssey") visually haunting chiller, based on the bestseller by master-of-suspense Stephen King ("The Stand," "Carrie," "The Shawshank Redemption"), is an undeniable contemporary classic. Newsweek Magazine calls this "the first epic horror film," full of indelible images, and a signature role for Nicholson whose character was recently selected by AFI for its' 50 Greatest Villains.
[produced_by] => Jan Harlan, Stanley Kubrick
[release_date] => 5/23/80
[screenplay_by] => Stephen King, Diane Johnson
[starring] => Jack Nicholson, Shelley Duvall, Danny Lloyd, Scatman Crothers
[studio] => Warner Bros.
[talking_about_count] => 5594
[username] => KubrickShining
[website] => http://bit.ly/shiningdvd
[were_here_count] => 0
[written_by] => Stephen King
[category] => Movie
[id] => 135347089926692
[name] => The Shining
[link] => http://www.facebook.com/KubrickShining
[likes] => 832526
[cover] => Array
(
[cover_id] => 2.24275514367E+14
[source] => http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash4/320182_224275514367182_46004854_n.jpg
[offset_y] => 85
)
)
[2] => Array
(
[about] => The official Facebook Page for The Shining | All work and no play makes Jack a dull boy.
[awards] => (1981) Saturn Award, Best Supporting Actor, Scatman Crothers
[can_post] => 1
[description] => Get The Shining at the WB Shop: http://bit.ly/shiningdvd
[directed_by] => Stanley Kubrick
[genre] => Horror, Suspense/Thriller
[is_published] => 1
[plot_outline] => All work and no play makes Academy Award-winner Jack Nicholson ("As Good As It Gets," "Batman"), the caretaker of an isolated resort, go way off the deep end, terrorizing his young son and wife Shelley Duvall ("Roxanne"). Master filmmaker Stanley Kubrick's ("Full Metal Jacket," "2001: A Space Odyssey") visually haunting chiller, based on the bestseller by master-of-suspense Stephen King ("The Stand," "Carrie," "The Shawshank Redemption"), is an undeniable contemporary classic. Newsweek Magazine calls this "the first epic horror film," full of indelible images, and a signature role for Nicholson whose character was recently selected by AFI for its' 50 Greatest Villains.
[produced_by] => Jan Harlan, Stanley Kubrick
[release_date] => 5/23/80
[screenplay_by] => Stephen King, Diane Johnson
[starring] => Jack Nicholson, Shelley Duvall, Danny Lloyd, Scatman Crothers
[studio] => Warner Bros.
[talking_about_count] => 5594
[username] => KubrickShining
[website] => http://bit.ly/shiningdvd
[were_here_count] => 0
[written_by] => Stephen King
[category] => Movie
[id] => 135347089926692
[name] => The Shining
[link] => http://www.facebook.com/KubrickShining
[likes] => 832526
[cover] => Array
(
[cover_id] => 2.24275514367E+14
[source] => http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash4/320182_224275514367182_46004854_n.jpg
[offset_y] => 85
)
)
)
I get this info from the open graph api from Facebook.
$matched_movies_array does not contain the movie names. So in_array will never pass.
Try something like:
$movieIds = array();
foreach($user_movie_info['data'] as $movie) {
similar_text($movie_facebook_page['genre'], $movie['genre'], $percent);
if ($percent > 30) {
echo $movie_facebook_page['genre']. "" ."</br>";
echo $movie['genre']. "" ."</br>";
echo $percent. "" ."</br>";
echo "match! </br></br>";
// add all movie information to matched array, only if its not already present
if (!in_array($movie_facebook_page['id'], $movieIds)) {
$movieIds[] = $movie_facebook_page['id'];
array_push($matched_movies_array, $movie_facebook_page);
}
} //foreach
Or maybe even better:
$id = $movie_facebook_page['id'];
if (!isset($matched_movies_array[$id])) {
$matched_movies_array[$id] = $movie_facebook_page;
}
The in_array() function doesn't work searching for a string in a multi-dimensional array. Take this for example:
$find = array("name" => "test");
$matches = array(array("name" => "test"), array("name" => "test2"));
echo (in_array($find['name'], $matches)) ? "found" : "not found";
echo "<br /><br />";
echo (in_array($find, $matches)) ? "found" : "not found";
The first echo is "not found", the second one is "found". You should use your entire $movie_facebook_page array as the needle.
i use imdb api
$homepage = file_get_contents('http://www.imdbapi.com/?i='.$imdbID);
$arr = json_decode($homepage);
In $arr i have all data about related movie.
Maguire [Year] => 1996 [Rated] => R [Released] => 13 Dec 1996 [Genre] => Comedy, Drama, Romance, Sport [Director] => Cameron Crowe [Writer] => Cameron Crowe [Actors] => Tom Cruise, Cuba Gooding Jr., Renée Zellweger, Kelly Preston [Plot] => When a sports agent has a moral epiphany and is fired for expressing it, he decides to put his new philosophy to the test as an independent with the only athlete who stays with him. [Poster] => http://ia.media-imdb.com/images/M/MV5BMTkxNjc2NjQwOF5BMl5BanBnXkFtZTcwMDE2NDU2MQ##._V1_SX320.jpg [Runtime] => 2 hrs 19 mins [Rating] => 7.2 [Votes] => 97329 [ID] => tt0116695 [Response] => True )
what i want is that reaching specified key's value.
Is there a function like that? For example , i will give the key=> Actors and get all actors?
:/ Like this?
$homepage = file_get_contents('http://www.imdbapi.com/?i='.$imdbID);
$arr = json_decode($homepage, true);
print($arr['Actors']);