Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Date specific output: PHP

Options
  • 10-11-2006 6:26pm
    #1
    Registered Users Posts: 35,524 ✭✭✭✭


    Hi, I'm trying to help a friend out with his new site, he has just converted from asp to php and he thinks that I know all about php, which I don't! So I said that I'd ask around.

    He has a database of entries of people's birthdays and he wants to be able to get the date and check if there is a birthday on the day and output a happy birthday message.

    Here's the asp code but I don't expect you to give me the answer:
    <%
    
     'dim theDay, theMonth, strSQL
    
     theDay = Day(Date())
    
     theMonth = Month(Date())
    
     if CINT(theDay) < 10 then theDay = "0" & theDay
    
     if CINT(theMonth) < 10 then theMonth = "0" & theMonth
    
     
     strSQL = "SELECT fEvent FROM tbl_dayevent WHERE fDate = '" & theMonth & " " & theDay & "'"
    
     'Dim rstRecords
    
     Set rstRecords = Server.CreateObject("ADODB.Recordset")
    
     rstRecords.ActiveConnection = "driver={MySQL ODBC 3.51 Driver};option=4;server=localhost;user=userr;pwd=xxx;DATABASE=databaser;"
    
     rstRecords.Source = strSQL
    
     rstRecords.CursorType = 0
    
     rstRecords.CursorLocation = 2
    
     rstRecords.LockType = 1
    
     rstRecords.Open() 
    
    
     if NOT rstRecords.EOF then                
    
                 response.write(rstRecords("fEvent") & "... Happy Birthday!")
    
     end if
    
    
     rstRecords.Close
    
     set rstRecords = Nothing
    
    %>
    

    But if you could point me in the direction he needs so that I can get some google searches going that'd be great. I've searched for 'date specific output' but no joy. What should I be looking for to solve this?

    Thanks.


Comments

  • Registered Users Posts: 32,136 ✭✭✭✭is_that_so


    Here's a bit of code to help you.

    DB connection stuff and fields(connection was originally done using Access)

    $db = 'dbpath';
    $dbArray = array();
    $db_conn = new COM("ADODB.Connection");
    $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("./$db").";";
    $db_conn->open($connstr);
    $rS = $db_conn->execute("sql query;");
    $f1 = $rS->Fields(0);
    $f2 = $rS->Fields(1);
    while (!$rS->EOF)
    {
    array_push($dbArray, $f2->value ,$f1->value);
    $rS->MoveNext();

    }
    $rS->Close();
    $db_conn->Close();
    return $dbArray;


    Date stuff


    $today = explode("-",$today);
    $year = $today[2];
    $month = $today[1];
    $day = $today[0];
    $start_month=$month;

    Also check out the PHP date page


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    What format are the dates stored in the database? You want to get todays date with something like[php]echo date("Y-m-d");[/php] and then store that to a variable, say $date, and then use the code similarly above as something like

    [php]$sql="SELECT * FROM tbl_name WHERE date_field = $date;[/php]

    And then use an if - else function to print happy birthday or whatever if the result contains any data or nothing if it doesn't.


Advertisement