Jump to content

keeps21

Members
  • Posts

    91
  • Joined

  • Last visited

About keeps21

  • Birthday 02/01/1985

Contact Methods

  • Website URL
    http://www.techiesknow.co.uk

Profile Information

  • Gender
    Male
  • Location
    Durham, UK

keeps21's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi A really basic question, with regards to best practice, but I can't find an answer anywhere. Should the charset in my website be set to match the charset used by my database? E.g. Database is utf-8, so website should be set to utf-8?
  2. I have an application which allows users to make a booking for a room. user picks the date, start time and end time. What I want to do is create a colour coded 'table of availability'. Basically draw a table, showing 'blocks' of 1 hour intervals, if that hour has been booked it is unavailable, color red, otherwise color green. The bookings are stored in the database table 'bookings' 'booking_id | date | start_time | end_time | user_id | room_id | ------------------------------------------------------------------- 1 | 2009-09-30 | 16:00:00 | 17:00:00 | 1 | 1 | 2 | 2009-09-30 | 12:00:00 | 14:00:00 | 1 | 1 | I'm pulling the data from the database for that room and date into an array SELECT * FROM bookings WHERE date= 2009-09-30 would give an array: array( '0' => array('booking_id' => '1', 'date' => '2009-09-30', 'start_time' => '16:00:00', 'end_time' => '17:00:00', 'user_id' => '1', 'room_id => '1', ); '1' => array('booking_id' => '2', 'date' => '2009-09-30', 'start_time' => '12:00:00', 'end_time' => '14:00:00', 'user_id' => '1', 'room_id => '1', ); ) ; what i need to do is write out a table where each cell represents an hour in time and color cells in which represent hours between start_time, and end_time in the array using a loop. I just can't get my head around the loop required. Any help would be greatly appreciated. Thanks
  3. That would be the better option. But you could store all the keywords in one field. Then when pulling the keywords out of the database "explode" that field to get the individual keywords.
  4. As per the title. I need to remove the text between the first <h1></h1> tags in the input string - but leave any further <h1></h1> tags in the string as they are. Any help would be appreciated. Thanks.
  5. You're using $cid in your query on line 26 but $cid hasn't been definied anywhere, in other words $cid doesn't exist.
  6. Try using this function function clean_data($data) { $code_entities_match = array(' ','--','"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','='); $code_entities_replace = array('','','','','','','','','','','','','','','','','','','','','','','','','',''); $clean = str_replace($code_entities_match, $code_entities_replace, $data); return $clean; } // You would use it like follows $clean_data = clean_data($_POST['find']);
  7. Further amendments. <?php # Set default timezone date_default_timezone_set('Europe/London'); ini_set('display_errors', 1); error_reporting(E_ALL|E_STRICT); // Convert date function get_date($date) { return date('Y-m-d H:i:s', strtotime($date)); } // Convert date to timestamp function convert_to_timestamp($date) { return strtotime($date); } // Parse feed function parse_feed($feed) { $rss = simplexml_load_file($feed); if ($rss) { // Feed is valid and well formed $newsfeed = array(); $i=0; foreach ($rss->channel->item as $item) { $newsfeed[$i]['title'] = $item->title; $newsfeed[$i]['pubDate'] = get_date($item->pubDate); $newsfeed[$i]['timestamp'] = convert_to_timestamp($item->pubDate); $newsfeed[$i]['description'] = $item->description; $newsfeed[$i]['link'] = $item->link; $i++; } return $newsfeed; } } // $feeds array will be populated from the database in the future $feeds = array('google' => 'http://news.google.co.uk/news?um=1&ned=uk&hl=en&q=football&output=rss', 'bbc' => 'http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/front_page/rss.xml' ); $merged = array(); foreach ($feeds as $feed) : $fe = parse_feed($feed); foreach ($fe as $f): $merged[] = $f; endforeach; endforeach; // Sort the data with volume descending, edition ascending // Add $data as the last parameter, to sort by the common key foreach ($merged as $key => $row) { $pubdate[$key] = $row['pubDate']; } array_multisort($pubdate, SORT_DESC, SORT_STRING, $merged); // Output array foreach($merged as $m) : if (time() - $m['timestamp'] <= 3600) { // Last Hour if (!isset($last)) { echo '<h1>Last Hour</h1>'; $last = 1; } echo date( 'd-m-Y H:i', $m['timestamp']) . ' - ' . $m['title'] . '<br />'; } elseif (time() - $m['timestamp'] <= 7200 && time() - $m['timestamp'] > 3600 ) { // between 1 and 2 hours if (!isset($onetotwo)) { echo '<h1>1-2 Hours Old</h1>'; $onetotwo = 1; } echo date( 'd-m-Y H:i', $m['timestamp']) . ' - ' . $m['title'] . '<br />'; } elseif (time() - $m['timestamp'] <= 14400 && time() - $m['timestamp'] > 7200 ) { // between 2 and 4 hours if (!isset($twotofour)) { echo '<h1>2-4 Hours Old</h1>'; $twotofour = 1; } echo date( 'd-m-Y H:i', $m['timestamp']) . ' - ' . $m['title'] . '<br />'; } else { // over 4 hours old if (!isset($overfour)) { echo '<h1>Over 4 Hours Old</h1>'; $overfour = 1; } echo date( 'd-m-Y H:i', $m['timestamp']) . ' - ' . $m['title'] . '<br />'; } endforeach;
  8. Now amended to show items in groups. Last Hour 1-2 Hours Old 2-4 Hours Old Over 4 Hours Old Code is shown below - I'd be very grateful for any suggestions,improvements or advice. <?php // Convert date function get_date($date) { return date('Y-m-d H:i:s', strtotime($date)); } // Convert date to timestamp function convert_to_timestamp($date) { return strtotime($date); } // Parse feed function parse_feed($feed='') { $rss = simplexml_load_file($feed); if ($rss) { // Feed is valid and well formed $newsfeed = array(); $i=0; foreach ($rss->channel->item as $item) { $newsfeed[$i]['title'] = $item->title; $newsfeed[$i]['pubDate'] = get_date($item->pubDate); $newsfeed[$i]['timestamp'] = convert_to_timestamp($item->pubDate); $newsfeed[$i]['description'] = $item->description; $newsfeed[$i]['link'] = $item->link; $i++; } return $newsfeed; } } // Feeds to parse $google = parse_feed('http://news.google.co.uk/news?um=1&ned=uk&hl=en&q=football&output=rss'); $bbc = parse_feed('http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/front_page/rss.xml'); // Array to store feed data in $merged = array(); // Add feed 1 data to array foreach($google as $data) : $merged[] = $data; endforeach; // Add feed 2 data to array foreach($bbc as $data) : $merged[] = $data; endforeach; // Sort the data with volume descending, edition ascending // Add $data as the last parameter, to sort by the common key foreach ($merged as $key => $row) { $pubdate[$key] = $row['pubDate']; } array_multisort($pubdate, SORT_DESC, SORT_STRING, $merged); // Output array foreach($merged as $m) : if (time() - $m['timestamp'] <= 3600) { // Last Hour if ($last != 1) { echo '<h1>Last Hour</h1>'; $last = 1; } echo $m['pubDate'] . ' - ' . $m['title'] . '<br />'; } elseif (time() - $m['timestamp'] <= 7200 && time() - $m['timestamp'] > 3600 ) { // between 1 and 2 hours if ($onetotwo != 1) { echo '<h1>1-2 Hours Old</h1>'; $onetotwo = 1; } echo $m['pubDate'] . ' - ' . $m['title'] . '<br />'; } elseif (time() - $m['timestamp'] <= 14400 && time() - $m['timestamp'] > 7200 ) { // between 2 and 4 hours if ($twotofour != 1) { echo '<h1>2-4 Hours Old</h1>'; $twotofour = 1; } echo $m['pubDate'] . ' - ' . $m['title'] . '<br />'; } else { // over 4 hours old if ($overfour != 1) { echo '<h1>Over 4 Hours Old</h1>'; $overfour = 1; } echo $m['pubDate'] . ' - ' . $m['title'] . '<br />'; } endforeach;
  9. This is the code I've come up with - and it seems to be working alright for me. Can anyone make any suggestions as to improvements - especially with regards to the way I'm handling the date. Cheers Here's the code. <?php // Convert date function get_date($date) { // Date is in the format Mon, 08 Jun 2009 $str = $date; $strArray = explode(' ', $str); array_shift($strArray); array_pop($strArray); switch ($strArray[1]) { case 'Jan': $strArray[1] = '01'; break; case 'Feb': $strArray[1] = '02'; break; case 'Mar': $strArray[1] = '03'; break; case 'Apr': $strArray[1] = '04'; break; case 'May': $strArray[1] = '05'; break; case 'Jun': $strArray[1] = '06'; break; case 'Jul': $strArray[1] = '07'; break; case 'Aug': $strArray[1] = '08'; break; case 'Sep': $strArray[1] = '09'; break; case 'Oct': $strArray[1] = '10'; break; case 'Nov': $strArray[1] = '11'; break; case 'Dec': $strArray[1] = '12'; break; default: break; } // re-form date $date = $strArray[2].'-'.$strArray[1].'-'.$strArray[0].' '.$strArray[3]; return $date; } // Parse feed function parse_feed($feed='') { $rss = simplexml_load_file($feed); if ($rss) { // Feed is valid and well formed $newsfeed = array(); $i=0; foreach ($rss->channel->item as $item) { $newsfeed[$i]['title'] = $item->title; $newsfeed[$i]['pubDate'] = get_date($item->pubDate); $newsfeed[$i]['description'] = $item->description; $newsfeed[$i]['link'] = $item->link; $i++; } return $newsfeed; } } // Feeds to parse $google = parse_feed('http://news.google.co.uk/news?um=1&ned=uk&hl=en&q=football&output=rss'); $bbc = parse_feed('http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/front_page/rss.xml'); // Array to store feed data in $merged = array(); // Add feed 1 data to array foreach($google as $data) : $merged[] = $data; endforeach; // Add feed 2 data to array foreach($bbc as $data) : $merged[] = $data; endforeach; // Sort the data with volume descending, edition ascending // Add $data as the last parameter, to sort by the common key foreach ($merged as $key => $row) { $pubdate[$key] = $row['pubDate']; } array_multisort($pubdate, SORT_DESC, SORT_STRING, $merged); // Output array foreach($merged as $m) : echo $m['pubDate'] . ' - ' . $m['title'] . '<br />'; endforeach;
  10. I don't think so. What I'm wanting to do is merge a number of feeds together, and output the latest x items ordered by date, most recent first. I'll be taking a feed, reading the feed data into the array, and then repeating for a number of feeds. I then want to sort the order of the array.
  11. I have an array which I want to sort by the index 'pubDate' from most recent to oldest But I'm not sure how to do it. Here is the array I'm working with Array ( [0] => Array ( [title] => SimpleXMLElement Object ( [0] => Warriors net two more signings ) [pubDate] => SimpleXMLElement Object ( [0] => Mon, 08 Jun 2009 10:10:15 GMT ) [description] => SimpleXMLElement Object ( ) [link] => SimpleXMLElement Object ( [0] => http://www.whitleywarriors.net/news/view/id/202/warriors-net-two-more-signings.html ) ) [1] => Array ( [title] => SimpleXMLElement Object ( [0] => New Website Launched ) [pubDate] => SimpleXMLElement Object ( [0] => Mon, 01 Jun 2009 11:16:50 GMT ) [description] => SimpleXMLElement Object ( ) [link] => SimpleXMLElement Object ( [0] => http://www.whitleywarriors.net/news/view/id/200/new-website-launched.html ) ) [2] => Array ( [title] => SimpleXMLElement Object ( [0] => Warrior Spike ) [pubDate] => SimpleXMLElement Object ( [0] => Wed, 27 May 2009 22:17:08 GMT ) [description] => SimpleXMLElement Object ( ) [link] => SimpleXMLElement Object ( [0] => http://www.whitleywarriors.net/news/view/id/199/warrior-spike.html ) ) [3] => Array ( [title] => SimpleXMLElement Object ( [0] => Legends return to the ice ) [pubDate] => SimpleXMLElement Object ( [0] => Wed, 27 May 2009 22:16:15 GMT ) [description] => SimpleXMLElement Object ( ) [link] => SimpleXMLElement Object ( [0] => http://www.whitleywarriors.net/news/view/id/198/legends-return-to-the-ice.html ) ) [4] => Array ( [title] => SimpleXMLElement Object ( [0] => Captain Dunn - Sample and Wilson to return ) [pubDate] => SimpleXMLElement Object ( [0] => Thu, 21 May 2009 10:46:56 GMT ) [description] => SimpleXMLElement Object ( ) [link] => SimpleXMLElement Object ( [0] => http://www.whitleywarriors.net/news/view/id/192/captain-dunn--sample-and-wilson-to-return.html ) ) [5] => Array ( [title] => SimpleXMLElement Object ( [0] => Two in, one out ) [pubDate] => SimpleXMLElement Object ( [0] => Sat, 16 May 2009 14:05:23 GMT ) [description] => SimpleXMLElement Object ( ) [link] => SimpleXMLElement Object ( [0] => http://www.whitleywarriors.net/news/view/id/180/two-in-one-out.html ) ) ) How would I do this?
  12. Just thinking about creating a website to take in multiple rss feeds, merging the data into an array and then outputting the latest 10 or so. Pseudocode # Initialise feedArray $feedArray = array(); foreach feed : # Grab and read feed # Add feed data into $feedArray - ie title, link, description, date endforeach; # sort feed array # output foreach item in feedarray : #output data endforeach; Does that make sense?
  13. When opening the page is ?cid=1 (where the id you want is 1) part of the query string in the address bar? If not then $_GET['cid'] hasn't been defined, which is why you're getting the undefined index message.
×
×
  • 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.