mschroeder 251 Bestower of Knowledge Team Colleague

Is there a reason you are not using DateTime and trying to use strtotime now?

strtotime is going to return a timestamp, not a DateTime object, so you are not going to be able to use $dteDiff as a DateInterval object like you posted originally.

mschroeder 251 Bestower of Knowledge Team Colleague

$dteStart->diff($dteEnd); returns an instance of DateInterval

If you want the hours from the DateInterval object you can use either of these formatting options, depending on the output you want and a call to DateInterval::format ( string $format )

H - Hours, numeric, at least 2 digits with leading 0 - 01, 02, 23
h - Hours, numeric - 1, 3, 23

echo $dteDiff->format('%h')

mschroeder 251 Bestower of Knowledge Team Colleague

It sounds like you have a file with 10000+ lines in it, that you need to split into 50 line chunks and save to new files...

If the file is well over your php memory limit, reading the whole thing into memory will only cause you headaches.

I'd highly suggest using SplFileObject to iterate over the file line by line. This will give you a much smaller memory footprint.

Create a blank file also using SplFileObject, iterate over 50 lines of the original file, writing each line to the new blank file.
Keep a counter of how many lines you've read through. When you've reached 50, simply increment the blank file you're using.

I'll be happy to share code examples.

mschroeder 251 Bestower of Knowledge Team Colleague

What is the purpose of flushing the output buffer in a controller? Are you trying to use codeigniter in an HMVC fasion and include one controller within another?

mschroeder 251 Bestower of Knowledge Team Colleague

For the sake of learning.

I think you're whole architecture and thought process on this is wrong.
There is a complete violation of single responsibility in all of your classes.

We can quickly break this into three responsibilities.

  1. Entity\Member - an entity which models a member
  2. Validator\Contact - a class which handles validating if two members can communicate
  3. Entity\Message - an entity which models a message

Example\Entity\Member.php

<?php

namespace Example\Entity;

class Member
{
    //Properties and methods representing a single unique member.
}

Example\Validator\Contact.php

<?php

namespace Example\Validator;

use Example\Entity\Member;

class Contact
{
    public function validate( Member $from, Member $to )
    {
        $communicate = false;

        //Logic that looks at both members and determines if they can communicate.
        //Sets communicate to true/false depending on results of logic

        return $communicate;
    }
}

Example\Entity\Message.php

<?php

namespace Example\Entity;

use Example\Entity\Member;

class Message
{
    //Properties and methods representing a single unique message
    //Should all for a to and from to be set

    protected $to;
    protected $from;

    setTo( Member $to ){
        $this->to = $to;
        return $this;
    }

    // Etc.

    send(){
        //Violates single responsibility but just used for illustration.
    }
}

Usage Example:

<?php
//Example\index.php

namespace Example;

use Example\Entity\Member;
use Example\Entity\Message;
use Example\Validator\Contact;

$memberFrom = new Member();
$memberTo = new Member();

$validator = new Contact();

if( $validator->validate( $memberFrom, $memberTo ) ){
    $message = new Message();
    $message->setFrom( $memberFrom );
    $message->setTo( $memberTo );
    $message->setBody( 'lorem ipsum' );
    $message->send();
}
mschroeder 251 Bestower of Knowledge Team Colleague

If you want the currently executing PHP file you can use the magic constant __FILE__ (http://php.net/manual/en/language.constants.predefined.php) which will give the filesystem path.

OR

If you want to link to the current file in a url fashion you can use $_SERVER['PHP_SELF'] (http://php.net/manual/en/reserved.variables.server.php)
e.g. if the url is http://www.domain.com/script.php then $_SERVER['PHP_SELF'] will contain /script.php

mschroeder 251 Bestower of Knowledge Team Colleague

While a threaded set of comments like this is probably best handled by a NoSQL database the necessity to deal with them in a relational database has exsisted for some time.

I would suggest looking at either Path Enumeration or a Closure Table to properly model a threaded conversation to n depth and still be able to CRUD the data with ease. Check out the following presentation as it provides some good illustrations and examples of four ways to solve this, including the two I have mentioned. http://www.slideshare.net/billkarwin/models-for-hierarchical-data

The presentation author has also written a detailed example on his blog of rendering a Closure Table. http://karwin.blogspot.com/2010/03/rendering-trees-with-closure-tables.html

mschroeder 251 Bestower of Knowledge Team Colleague

From a high level, your class is trying to accomplish to much in a single place. Check out the concept of SOLID (http://www.freeklijten.nl/home/2012/03/23/SOLID-The-S-is-for-Single-responsibility)

What you should ultimately end up with is a set of classes that allow you to work with emails in the most generic of ways. An Email object would represent an email and it's fields only. This should probably implement a standard interface so you can develop multiple email objects, e.g. PlainText, Html, Multi-part etc. These would extend a base class or implement some kind of inteface to ensure they have certain basic methods.

From there you would have an object that represents a mail server and is responsible for sending an Email Object. For example EmailTransport. Email transport might be setup to use different adapters that allow it to interact with multiple server types, sendmail, smtp, mock(for saving an email object to a file for testing), and mail(). This can be designed using the Adapter pattern.

For validation and filtering you would want two finds of objects, One that is able to deal with specific pieces of validation. Again you'd have multiple validators each with a single functionality. Filters would be setup the same way.

This is really high level and a lot to digest but these are some of the common things I see wrong with OOP code in the PHP world and I hope this helps to set you on the right path.

<?php

    namespace Daniweb\Email;

    interface EmailInterface
    {
        protected $to;
        protected …
mschroeder 251 Bestower of Knowledge Team Colleague

The easiest way to implement this, if scaling is not an issue would be to have a single database, with a table that identifies the possible sites. And then an identifier on all of the necessary records connecting the products to a particular site. On the front-ends you would simply filter based on the SiteId etc. If you make database structure changes all sites receive the changes simultaneously. If you intend to store a lot of records and by a lot of records I mean millions then you will need consider scaling or sharding etc.

The other option is to implement each site in its own identical database, however keeping the structures in-line if the there will be more than two sites can become troublesome. In your application you'd simply need to know the different database server connections and the logic to CRUD a record would be relatively similiar to the first scenario, except it would want to pass the record to each database connection independently.

Having the ability to register database connections as a pool would be critical to pulling off the second scenario, as you would want a single transaction to be pushed to all databases and if one database fails for some reason you would need a scenario to roll back all of the changes. MySQL transactions in InnoDB might be worth looking at for data integrity. All depends on your needs.

mschroeder 251 Bestower of Knowledge Team Colleague
echo $array[79]->value;

Something like that should do the trick, obviously depends on what the variable that contains the array is named.

mschroeder 251 Bestower of Knowledge Team Colleague

Using the idea of a Honey Pot has always been a pretty effective way to prevent comment form spam. Basically add one or more additional form fields that are hidden to the browsing user that should always be blank. When a form is submitted with those fields filled in, reject the submission.

Venom Rush commented: Great idea! +2
mschroeder 251 Bestower of Knowledge Team Colleague

I used to be a big advocate of Eclipse and/or Zend Studio, but I've since switched to Sublime Text 2 and could not be happier. However, its more of a text editor than a traditional IDE.

mschroeder 251 Bestower of Knowledge Team Colleague

If you are using PHPUnit, then looking at the code coverage reports would be your best bet. These will show you down to the line what your tests are actually covering.

Actually counting the number of methods is pointless as in a well tested solution you'll have significantly more tests than you will actual methods in your classes.

mschroeder 251 Bestower of Knowledge Team Colleague
mschroeder 251 Bestower of Knowledge Team Colleague

In the many years I've been developing with php, mailing is always a big pain point I see. As much as I like to advocate learning how to implement something yourself to have a better understanding of how things work and then looking for a more rigorously tested solution or building one, this is one of the few situations I'd say skip learning how to implement a mailing solution well. The specs are vast and complicated and if you're just trying to send emails it is easier to use a 3rd party library that will simplify all of it. If you simply rely on php's mail() function you will have nothing but headaches dealing with bounces and spam hits.

I really like the SwiftMailer (http://swiftmailer.org/) library. It is a great library with robust functionality that has seen a lot of recent attention thanks to the Symfony2 framework.

Zend_Mail is also a great package (http://framework.zend.com/manual/en/zend.mail.html) however I'm not sure how easy/difficult it would be to use it standalone. I'm sure there are tutorials that would explain what is necessary.

PHP Mailer is also one of the other big players. (http://phpmailer.worxware.com/)

mschroeder 251 Bestower of Knowledge Team Colleague

As I said previously....

Oh EACH remote machine you want to access your wamp machine from, you will need to modify the hosts file.

The only other option is to create a DNS server just for .local domains and have your computers route through that. However, this is overkill when you just need access for a few machines.

mschroeder 251 Bestower of Knowledge Team Colleague

You have modified the hosts file on the second computer and not the server 192.168.1.4 correct?

mschroeder 251 Bestower of Knowledge Team Colleague

Oh EACH remote machine you want to access your wamp machine from, you will need to modify the hosts file.
Add a new line: ###.###.###.### project.local where ###.###.###.### is the IP address of the remote machine on your lan. So a 10.x.x.x. or a 192.x.x.x etc.

If the virtualhost is set to listen on *:80 you won't have an issue. If it is set to listen on *:81 you will need to add :81 after your project.local domain.

mschroeder 251 Bestower of Knowledge Team Colleague

The simplest solution on windows would be to modify the hosts file so that project.local resolves to the ip of the wamp machine. I also seem to recall wamp having to be set into "online" mode to serve files outside of localhost.

mschroeder 251 Bestower of Knowledge Team Colleague
$imagename = end(explode('/',$_POST['img']));
$img = mysql_real_escape_string($imagename);

Does not resolve the pass by reference issue given the ops original code.

$parts = explode('/',$_POST['img'])
$imagename = end( $parts );
$img = mysql_real_escape_string($imagename);

Should resolve the issue as the return of explode is not passed directly into another function call.

mschroeder 251 Bestower of Knowledge Team Colleague

Can't really help you without seeing what the code before, on and after line 8 looks like.

Without seeing code I'm assuming your passing something like the return of explode() directly into another function. e.g. $foo = array_shift( explode( '.', $bar ) );

mschroeder 251 Bestower of Knowledge Team Colleague

What kind of environment is your server running? If the host is using the suPHP module instead of the standard apache DSO module then your scripts execute as your user. So any files/directories may be writable, without having to be 777 etc.

mschroeder 251 Bestower of Knowledge Team Colleague

Don't get me wrong. CI works and there are some great things built on it. But building a maintanable modular application is a nightmare. Testing is nearly impossible and spending time to make things testable often results in a huge dependency list. But, where there is a will there is a way and often getting a product to the market fast takes precedence.

mschroeder 251 Bestower of Knowledge Team Colleague

I've had extensive experience with all three of those frameworks.

Symfony2 - At the moment Symfony2 is the best framework I've used. The biggest feature of the whole "framework" is that it is nothing more than a collection of bundles architected together. It is extremely powerful and flexible, and you can replace pretty much any aspect of the system with your own implementations, but if you do not have a serious OOP background as well as a desire to learn how to use a DIC etc then Symfony2 is not for you. It can be a challenge to deploy and there is a STEEP learning curve, but once you've invested some time it is very hard to use other frameworks.

ZF1 - Used to be my favorite framework because of the structure and the access to documentation and users. The lack of native php namespaces and some of the design decisions made some of the components feel hackish in their implementations, but it worked and it worked well. However my experience with ZF2 has been much like Symfony2 but they are vastly different from one another and ZF2 has yet to have a "stable" release.

CI - I started using this framework when I started at my current employer. Personally I find it to be unorganized and convoluted (var_dump a get_instance() call just and look at the recursion and repetition in the array) . There are lots of 3rd party libraries that attempt to bring it more in line with …

mschroeder 251 Bestower of Knowledge Team Colleague

If you are using a MY_Controller with CI already, add a property called $ignore_cookies defaulting it to FALSE. In your controller setting the $ignore_cookies variable to TRUE will prevent the cookies from being set.

Extend /system/core/Security.php CI_Security with a MY_Security and override the csrf_set_cookie() method.

<?php

class MY_Security {

    public function __construct()
    {
        parent::__construct();
    }

    public function csrf_set_cookie()
    {

        $CI =& get_instance();

        if( !isset( $CI->ignore_cookies ) || (bool) $CI->ignore_cookies === FALSE ){
            return parent::csrf_set_cookie();
        }

        log_message('debug', "CRSF cookie set skipped");

        return $this;
    }
}

Extend /system/libraries/Session.php CI_Session with a MY_Session and override the _set_cookie() method

<?php

class MY_Session extends CI_Session
{
    public function __construct()
    {
        parent::__construct();
    }

    public function _set_cookie( $cookie_data = NULL )
    {
        $CI =& get_instance();

        if( !isset( $CI->ignore_cookie ) || (bool) $CI->ignore_cookie === FALSE ){
            parent::_set_cookie( $cookie_data );
        }
    }
}

When CI serves a request it will proxy through the MY_* instances and then pass the requests on as necessary to the core functions. This should prevent any cookies from being set.

I did some stepping through the code and at a cursory glance this seems to the be two points where cookie headers get set on a normal request. Note: I did not give these a thorough testing and I believe the modifications to the security class will disable csrf protection for those particular requests.

mschroeder 251 Bestower of Knowledge Team Colleague

It would be much easier to answer this if there was a link to the actual content you were trying to scrape. Else we can provide only theoretical answers that won't do you much good in the practical application.

mschroeder 251 Bestower of Knowledge Team Colleague

A few points to consider.
CI documentation suggests using an underscore naming convention (Books_model) vs camelcasing like BooksModel. Models should also start with a capital letter and be followed only by lowercase letters.

Also your models should call the parent constructor.

//...
public function __construct() {
    parent::__construct();
}
//...

Finally for a method to accept a post array as a method argument it means your method should look like:

public function fooBar( $post ){
    //...
}

And would be used as:

$this->model->fooBar( $_POST ); //or the post object in CI
mschroeder 251 Bestower of Knowledge Team Colleague

If you have server access or a hosting company that will install libraries for your use then a great PHP option is to use Snappy it wraps the wkhtmltopdf library and the wkhtmltoimage library.

diafol commented: good link +14
mschroeder 251 Bestower of Knowledge Team Colleague

Since the media is part of a namespace you have to access that namespace to be able to access those nodes easily.

There are a few different ways for it to be achieved but I think this is the cleanest overall.

<?php

$feed = file_get_contents("http://news.yahoo.com/rss/europe");
$xml = new SimpleXmlElement($feed);

foreach ($xml->channel->item as $entry){
  $namespaces = $entry->getNameSpaces(true);
  $media = $entry->children($namespaces['media']); 
  echo $media->text;
  echo $media->credit;
}

Untested but you should get the general idea.

mschroeder 251 Bestower of Knowledge Team Colleague

@pritaeas
When you say output caching you mean caching the final rendered templates or caching the templates themselves?

I have always used twig behind Varnish servers which integrate very well with Symfony2 so I use a lot of ESI's to deal with my caching. Twig by default compiles all of your templates down to native php so that is also a kind of cache that vastly improves performance. I also usually run the twig php extension wherever possible to squeeze more performance out of it.

Apparently I don't get notifications when someone comments on threads I've posted in now... +1 for "upgrading functionality" I guess.

@ardav
I really like what is being done with composer and packagist they make PEAR feel archaic and remove the dependency on libraries that don't get updated fequently on shared servers because of dependency.

mschroeder 251 Bestower of Knowledge Team Colleague

Twig gets my vote by far. Having used a lot of different template languages for php it is the first one that really seems to get it right.

The syntax is concise but yet still very verbose. It is fast, but mostly it is extensible. Twig is a pleasure to write extensions for that keep the template language looking neat and tidy. Plus it is part of a major framework (Symfony2 Standard) and that ensures it will receive long-term attention and development.

mschroeder 251 Bestower of Knowledge Team Colleague

Assuming you are not confusing a table and a database, and that the databases all reside on one server, this is relatively easy to achieve.

Here is a quick example to illustrate the technique:

Database1 - Table people
DROP TABLE IF EXISTS `people`;

CREATE TABLE `people` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `age` int(3) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

LOCK TABLES `people` WRITE;
/*!40000 ALTER TABLE `people` DISABLE KEYS */;

INSERT INTO `people` (`id`, `name`, `age`)
VALUES
    (1,'jim smith',18),
    (2,'john doe',21),
    (3,'bill johnson',37);

/*!40000 ALTER TABLE `people` ENABLE KEYS */;
UNLOCK TABLES;
Database2 - Table people
DROP TABLE IF EXISTS `people`;

CREATE TABLE `people` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `age` int(3) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

LOCK TABLES `people` WRITE;
/*!40000 ALTER TABLE `people` DISABLE KEYS */;

INSERT INTO `people` (`id`, `name`, `age`)
VALUES
    (1,'mary smith',22),
    (2,'linda doe',40),
    (3,'rachel lynn',15);

/*!40000 ALTER TABLE `people` ENABLE KEYS */;
UNLOCK TABLES;
PHP
<?php
$mysqli = new mysqli("localhost", "user", "password");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query  = "SELECT * FROM database1.people;";
$query  .= "SELECT * FROM database2.people";

/* execute multi query */
if ($mysqli->multi_query($query)) {
    do {
        /* store first result set */
        if ($result = $mysqli->store_result()) {
            while ($row = $result->fetch_row()) {
                print_r($row);
            }
            $result->free();
        }
        /* print divider */
        if ($mysqli->more_results()) {
            printf("-----------------\n");
        }
    } while ($mysqli->next_result());
}

/* close …
mschroeder 251 Bestower of Knowledge Team Colleague

If you have access to the server to install new libraries or if you have a server admin who can address this for you, I highly suggest looking at the pdftk library. http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

Instead of trying to generate the entire page with php and get the styling correct, create a pdf form that has the labels laid out already, and form fields with the styling applied already. Then simply create an xfdf file (xml) with php and merge it with the templated pdf form using pdftk.

Perfect looking pdfs everytime. Don't forget to account for line lengths etc.

mschroeder 251 Bestower of Knowledge Team Colleague

In my experience, having developed complex systems from scratch, Zend, Symfony2, and CodeIgniter, I can tell you that it really depends on what you want your end result to be. If you build something from scratch you have total control over every aspect, this can be both good and bad, of the process and architecture.

It also depends on how you expect the project to grow, often what is attractive about 3rd party frameworks is the standardization. if you know Zend, you should be able to easily acclamate yourself to any Zend project. So if you need more developers you can focus on people who know your particular framework and only have to train them on the business implementations whereas if you're working in a homespun environment it will take a new developer a lot longer to come up to speed, and be productive.

There are other things to consider as well, performance, security, documentation, unit testing etc. Third party frameworks often have hundreds or thousands of contributors which is what makes them so robust.

As far as frameworks go, I really liked Zend until I started working with Symfony2. While I know there are complex sites built on CodeIgniter I really find it to be a subpar framework. Its nearly impossible to swap out core components with your own implementations, it will fight you every step of the way to test, and while it uses OOP principles it is as far from OOP as you can …

mschroeder 251 Bestower of Knowledge Team Colleague

A platform I've worked with in the past is http://zencoder.com/ but it is not free.

mschroeder 251 Bestower of Knowledge Team Colleague

No recursion necessary...

<?php

function getTotal( $integer )
{
	return array_product( range( 1, (int) $integer ) );
}

echo getTotal(9); //362880
mschroeder 251 Bestower of Knowledge Team Colleague

If you want to do this yourself then I suggest using wkhtmltopdf and/or wkhtmltoimage (http://code.google.com/p/wkhtmltopdf/). There is also a PHP library already developed to work with these libraries which can be had at https://github.com/KnpLabs/snappy

mschroeder 251 Bestower of Knowledge Team Colleague

Why reinvent the wheel and try to create a code style guide from scratch when there are plenty of sensical, logical and well documented style guides out there already that are accepted and in use in lots of projects?

All you'll do with such a non-standard design is create a barrier that if you ever need someone to work on your code they'll spend more time trying to figure out the style than what it is they're tasked to do.

diafol commented: good comment - especially about collaborative coding +14
mschroeder 251 Bestower of Knowledge Team Colleague

If your webhost does not support .htaccess and the web server is Apache...move to a better host.
If your webhost does not support .htaccess and the web server is not Apache, look to see what type of url rewriting it supports. If you still can't...move to a better host.

.htaccess or its equivalent is pretty much an industry standard these days.

Creating tons of index.php files in tons of nested directories, not only introduces a maintenance nightmare, but also introduces a security risk when it comes to fixing bugs they will need to be pushed through any file with duplicated code. This goes back to creating a maintenance nightmare.

mschroeder 251 Bestower of Knowledge Team Colleague

The curly brackets are called complex syntax. To use a an array item with a quoted identifier within a double quoted string is needs to be surrounded using { and }.

http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double

A more complete description is about 1/4 of the way down the page.

mschroeder 251 Bestower of Knowledge Team Colleague

You could create a table that stores a log of changes to a table or tables. Your trigger would simply add a log entry to the table and then you could have a php script on a cron that is looking at your log table to see if it should run some kind of processing action.

See http://answers.oreilly.com/topic/176-how-to-use-a-trigger-to-log-changes-to-a-table-in-mysql/ for a reasonable example.

mschroeder 251 Bestower of Knowledge Team Colleague

you might want to look at one of those PHP framework!

Maybe you should look at some of the cutting edge php frameworks like symfony2, Lithium or how Zend Framework 2 is developing, you will find very little if any mixing of responsibilities.

mschroeder 251 Bestower of Knowledge Team Colleague

First, your class is mixing to many responsibilities.
You should be passing an already established database into your quiz class if it is needed.
Second, Your class should not be responsible for rendering the form as well, this is another responsibility that is mixed.
Third, you could probably benefit from a more robust class design.

Think of the design like this:

  • A "quiz" is a composite of "questions" that are rendered into a singular form.
  • The quiz should be able to add and remove questions as well as do it in a batch fashion.
    • Questions may need to be of different types, therefore rendered individually. (Multiple Choice, Select One, Input a Value)
    • Think about a Question abstract or interface that all question types need to extend, they all have common functionality and/or methods but also specific details that need to be represented.
  • When rendering a quiz, the ultimate goal would be to have a template for each question type, and a template for a quiz as a whole which would render the question templates into a form template and create the output.

It sounds like a lot more work, but the end result with be a quiz structure where you will be able to swap pieces and parts with little to no hassle, and also add or replace the questions and templates without touching other portions of your code.

diafol commented: nice one - I learned a lot from that. :) +14
mschroeder 251 Bestower of Knowledge Team Colleague

You can't use an array index that is not defined. Period.
You would first need to do a check of the variable to see if it exists and is set before passing it to the function.

if( empty( $mouse["gene"]["genenames"] ) ){
    $mouse["gene"]["genenames"] = array();
}

That code will check if the index is empty (http://php.net/manual/en/function.empty.php), and if it doesn't exist it just creates it as an empty array.

<?php
if( empty( $mouse["gene"]["genenames"] ) ){
	$mouse["gene"]["genenames"] = array();
}

$toCount = toCount( $human["gene"]["genenames"], $mouse["gene"]["genenames"] );
mschroeder 251 Bestower of Knowledge Team Colleague
<?php

function foo( $bar = null, $baz = null, $qux = null ){
     //Check if variables are not null
     //Do something with the variables
}

Usage:

<?php
foo();
foo( $bar );
foo( $bar, $baz );
foo( $bar, $baz, $qux );
foo( null, $baz );
foo( null, null, $qux );

//etc etc...
mschroeder 251 Bestower of Knowledge Team Colleague

How about you show us the code you're using so we can formulate a solution.

mschroeder 251 Bestower of Knowledge Team Colleague

Since I just wrote this code answering your first question:

<?php
//Create an instance of now
//This is used to determine the current month and also to calculate the first and last day of the month
$now = new DateTime( 'now', new DateTimeZone( 'America/New_York' ) );

//Create a DateTime representation of the first day of the current month based off of "now"
$start = new DateTime( $now->format('m/01/Y'), new DateTimeZone( 'America/New_York' ) );

//Create a DateTime representation of the last day of the current month based off of "now"
$end = new DateTime( $now->format('m/t/Y'), new DateTimeZone( 'America/New_York' ) );

//Define our interval (1 Day)
$interval = new DateInterval('P1D');

//Setup a DatePeriod instance to iterate between the start and end date by the interval
$period = new DatePeriod( $start, $interval, $end );

//Iterate over the DatePeriod instance
foreach( $period as $date ){

	//Make sure the day displayed is greater than or equal to today
	//Make sure the day displayed is NOT sunday.
	if( $date >= $now && $date->format('w') != 0 ){
		echo $date->format( 'l, Y-m-d H:i:s' ).PHP_EOL;
	}
}
Saturday, 2011-11-12 00:00:00
Monday, 2011-11-14 00:00:00
Tuesday, 2011-11-15 00:00:00
Wednesday, 2011-11-16 00:00:00
Thursday, 2011-11-17 00:00:00
Friday, 2011-11-18 00:00:00
Saturday, 2011-11-19 00:00:00
Monday, 2011-11-21 00:00:00
Tuesday, 2011-11-22 00:00:00
Wednesday, 2011-11-23 00:00:00
Thursday, 2011-11-24 00:00:00
Friday, 2011-11-25 00:00:00
Saturday, 2011-11-26 00:00:00
Monday, 2011-11-28 00:00:00
Tuesday, 2011-11-29 00:00:00

This is easily adapted to answer your second question as well:

//Iterate over the DatePeriod instance
foreach( $period as $date ){

	//Make sure the day displayed is ONLY …
mschroeder 251 Bestower of Knowledge Team Colleague

This is why ajax and php are ill suited for a real-time chat solution. Because it has to make a new request every n seconds which means you're hitting the system fresh every time since php does not really maintain state between requests.

You would really want to look at Comet
http://en.wikipedia.org/wiki/Comet_(programming)
http://ajaxian.com/archives/comet-with-php

Or, implement some form of long-polling
http://blog.perplexedlabs.com/2009/05/04/php-jquery-ajax-javascript-long-polling/

mschroeder 251 Bestower of Knowledge Team Colleague

die() ends your script execution. It is the same thing as exit(). So when your script hits the line die("go shawdy it's your database"); it exits and never executes the rest fo the script. Replace the die call with echo 'go shawdy it's your database'; and do the same for the other two in your function.

mschroeder 251 Bestower of Knowledge Team Colleague

If you have installed the SQL Server driver from Microsoft than you need to use the sqlsrv_* functions as demonstrated here: http://social.technet.microsoft.com/wiki/contents/articles/accessing-sql-server-databases-from-php.aspx More specifically these functions http://php.net/manual/en/book.sqlsrv.php