Jump to content

jamesxg1

Members
  • Posts

    1,133
  • Joined

  • Last visited

About jamesxg1

  • Birthday 02/01/1994

Profile Information

  • Gender
    Male
  • Location
    Kent, England

jamesxg1's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. As Pikachu2000 said, parenthesis missing... Use the code below. <?php $mysql = mysql_real_connect('localhost', 'root', '***********', '*******'); if (!$mysql) { die('Could not connect: ' . mysql_error()); } ?>
  2. Thanks for responding Christian - Regarding the date collector, I know how to pull the data down but I'm stumped as to how to make it "break" upon each new date because there could be 5 matches in one day and 10 in another so there is no default break :S and I'm very very new to DOM at the minute :S Thanks Christian James.
  3. Hi guys, Been a while! I was wondering if anyone out there could help with an issue I'm having. Basically I am trying to scrape a page for football fixtures, everything is going very well except the football "dates". If you visit http://www.bbc.co.uk...league/fixtures you will see a grey tr column containing the dates for when matches start. As you will see Westham V Arsenal is the last match on Saturday the 6th of Oct then Southampton V Fulham is the first match for the 27th. So to grab all this data I have written the following (please excuse some of the crap in it - debugging purposes). <?php $url = "http://www.bbc.co.uk/sport/football/premier-league/fixtures"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $html = curl_exec($ch); curl_close($ch); $dom = new DOMDocument; libxml_use_internal_errors(true); @$dom->loadHTML($html); libxml_use_internal_errors(false); $xpath = new DOMXPath($dom); $query = $xpath->query('.//div[@id="fixtures-data"]'); $matches = array(); foreach ($query as $node) { $DateData = $xpath->query('//h2[@class="table-header"]', $node); $MatchParent = $xpath->query('//tbody/tr[@class="preview"]/td[@class="match-details"]', $node); $Kick = $xpath->query('//tbody/tr[@class="preview"]/td[@class="kickoff"]', $node); $Date = trim($DateData->item(0)->nodeValue); echo '**' . $DateData->length. '**<br />'; echo '**' . $Kick->length. '**<br />'; echo '**' . $MatchParent->length. '**'; for ($i = 0; $i <= ($MatchParent->length - 1) AND $i <= ($Kick->length - 1); $i++) { $Teams = str_replace(array(' V ', '\n'), '-', trim($MatchParent->item($i)->nodeValue)); $TeamPeices = explode('-', $Teams); $matches[$Date][] = array('Home' => trim($TeamPeices[0]), 'Away' => trim($TeamPeices[1]), 'KickOff' => trim($Kick->item($i)->nodeValue)); } } echo '<pre>' . print_r($matches, true) . '</pre>'; ?> When I run the script I get the following results..... **52** **319** **320** Array ( [saturday 6th October 2012] => Array ( [0] => Array ( [Home] => Man City [Away] => Sunderland [KickOff] => 12:45 ) [1] => Array ( [Home] => Chelsea [Away] => Norwich [KickOff] => 15:00 ) [2] => Array ( [Home] => Swansea [Away] => Reading [KickOff] => 15:00 ) [3] => Array ( [Home] => West Brom [Away] => QPR [KickOff] => 15:00 ) [4] => Array ( [Home] => Wigan [Away] => Everton [KickOff] => 15:00 ) [5] => Array ( [Home] => West Ham [Away] => Arsenal [KickOff] => 17:30 ) [6] => Array ( [Home] => Southampton [Away] => Fulham [KickOff] => 13:30 ) [7] => Array ( [Home] => Liverpool [Away] => Stoke [KickOff] => 15:00 ) [8] => Array ( [Home] => Tottenham [Away] => Aston Villa [KickOff] => 15:00 ) [9] => Array ( [Home] => Newcastle [Away] => Man Utd [KickOff] => 16:00 ) [10] => Array ( [Home] => Tottenham [Away] => Chelsea [KickOff] => 12:45 ) ... [310] => Array ( [Home] => Chelsea [Away] => Everton [KickOff] => 15:00 ) [311] => Array ( [Home] => Liverpool [Away] => QPR [KickOff] => 15:00 ) [312] => Array ( [Home] => Man City [Away] => Norwich [KickOff] => 15:00 ) [313] => Array ( [Home] => Newcastle [Away] => Arsenal [KickOff] => 15:00 ) [314] => Array ( [Home] => Southampton [Away] => Stoke [KickOff] => 15:00 ) [315] => Array ( [Home] => Swansea [Away] => Fulham [KickOff] => 15:00 ) [316] => Array ( [Home] => Tottenham [Away] => Sunderland [KickOff] => 15:00 ) [317] => Array ( [Home] => West Brom [Away] => Man Utd [KickOff] => 15:00 ) [318] => Array ( [Home] => West Ham [Away] => Reading [KickOff] => 15:00 ) ) ) All very good, except it is putting them all under one date, when I need it to add the correct dates as the array "head" as it were then have the fixture data as another array inside. Does anyone know how I can do this? Any help appreciated as I've tried everything. Thanks, James.
  4. It would usually contain something like 16:32 pm or 4:32 am for instance
  5. Got the same again :S Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1348068720) at position 7 (7): Unexpected character' in /home/sites/colewebdesigns.co.uk/public_html/wp-content/themes/footballclub-2.1/predictions.php:67 Stack trace: #0 /home/sites/colewebdesigns.co.uk/public_html/wp-content/themes/footballclub-2.1/predictions.php(67): DateTime->__construct('1348068720') #1 /home/sites/colewebdesigns.co.uk/public_html/wp-content/themes/footballclub-2.1/loop-match.php(12): include('/home/sites/col...') #2 /home/sites/colewebdesigns.co.uk/public_html/wp-includes/template.php(392): require('/home/sites/col...') #3 /home/sites/colewebdesigns.co.uk/public_html/wp-includes/template.php(366): load_template('/home/sites/col...', false) #4 /home/sites/colewebdesigns.co.uk/public_html/wp-includes/general-template.php(128): locate_template(Array, true, false) #5 /home/sites/colewebdesigns.co.uk/public_html/wp-content/themes/footballclub-2.1/single.php(23): get_template_part('loop', 'matc in /home/sites/colewebdesigns.co.uk/public_html/wp-content/themes/footballclub-2.1/predictions.php on line 67
  6. Returns the following: Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1348070008) at position 8 (0): Unexpected character' in /home/sites/colewebdesigns.co.uk/public_html/wp-content/themes/footballclub-2.1/predictions.php:66 Stack trace: #0 /home/sites/colewebdesigns.co.uk/public_html/wp-content/themes/footballclub-2.1/predictions.php(66): DateTime->__construct('1348070008') #1 /home/sites/colewebdesigns.co.uk/public_html/wp-content/themes/footballclub-2.1/loop-match.php(12): include('/home/sites/col...') #2 /home/sites/colewebdesigns.co.uk/public_html/wp-includes/template.php(392): require('/home/sites/col...') #3 /home/sites/colewebdesigns.co.uk/public_html/wp-includes/template.php(366): load_template('/home/sites/col...', false) #4 /home/sites/colewebdesigns.co.uk/public_html/wp-includes/general-template.php(128): locate_template(Array, true, false) #5 /home/sites/colewebdesigns.co.uk/public_html/wp-content/themes/footballclub-2.1/single.php(23): get_template_part('loop', 'matc in /home/sites/colewebdesigns.co.uk/public_html/wp-content/themes/footballclub-2.1/predictions.php on line 66
  7. Ok no worries, I'll give that a shot in a moment Thanks premiso.
  8. $KickOffMatches[2] needed to be rendered into a usable format, so I've used date to format it using a "stamp" of the unusable date format then I've strtotime the correctly formatted date.
  9. I usually do for my sites, but this is a friends site and I'm helping them out.
  10. Well without that we are spinning our wheels trying to assist you. You do know that the errors are generally logged to files as well. Depending on the WebServer, it should be in something like /var/log/apache2/error.log or /var/log/nginx/error.log or some form of that. Well, the info I do have is this: Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string but that is only a portion of the error to be fair. Thanks, James.
  11. I would have but where it was causing a serious obstruction on the site, I've had to remove it and use a series of IF statements to do the validations for the meantime. Sorry Premiso :S James.
  12. Hello fellow PHPFreaks, It's been a while! I've come across an issue, I'm trying to calculate the amount of time difference between 2 times. I have done the date side of things and I only need to compare times if the date matches the same date in the database but I'm having some trouble with the time side. This is what I was using (it worked fine for a day and I've just checked it and its now not working). $KickOff = (string) do_shortcode('[tb_match id=' . $post->ID . ']'); $KickOffMatches = array(); preg_match('/\<div class="date"\>(.*?)<\/div\>\<time\>(.*?)\<\/time\>/', $KickOff, $KickOffMatches); $FormattedDate = date('Y-m-d', strtotime($KickOffMatches[1])); $FormattedTime = date('H:i A', strtotime($KickOffMatches[2])); $AMPM = date('A', strtotime($KickOffMatches[2])); $RawDate = strtotime($FormattedDate); $RawTime = strtotime(date('H:i', strtotime($KickOffMatches[2]))); $start_date = new DateTime(date('H:i A')); $TD = $start_date->diff(new DateTime($KickOffMatches[2])); The area that is causing the issue is $start_date = new DateTime(date('H:i A')); $TD = $start_date->diff(new DateTime($KickOffMatches[2])); I've tried everything but all I'm getting is a fatal error. I was wondering if anyone here knew of a way that I could do this without using DateTime? Any help with this would be greatly appreciated! Many thanks, James.
  13. Could you post your problem code here please? Remember to use the PHP or CODE tags. James.
  14. It would be a great deal easier to read if you use print_r() to print it and then post back and I will take a look. echo '<pre>' . print_r($winfo['regyinfo']) . '</pre>'; James.
  15. Hi! Would you please describe in a bit more detail what your issue here is? It's probably just me not understanding here LOL. Also, I think it would be a good idea to use mysql_num_rows at some point. James.
×
×
  • 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.