Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Date specific output: PHP

  • 10-11-2006 06:26PM
    #1
    Registered Users, Registered Users 2 Posts: 35,522 ✭✭✭✭


    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, Registered Users 2 Posts: 32,132 ✭✭✭✭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