Advanced Search

Results 1 to 7 of 7

Thread: Adding PHP to change data in Date Input Calendar

  1. #1
    Join Date
    Jan 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Adding PHP to change data in Date Input Calendar

    Hello,

    Im building a CMS and one of the parts needs a date calendar so the user can input the start and end date of contracts.

    Im using one of the tools from this site which is Jason's Date Input Calendar and have posted the code below for you to see how its currently being used.

    Code:
    <script type="text/javascript" src="calendarDateInput.js">
    
    <script>DateInput('dateoriginal', true, 'YYYY-MM-DD')</script>
    All works fine, but I am trying to do is get the date to change when the client tries to edit this contract, to reflect the date that has been set in the database.

    So I was thinking something like this, but its not working:

    Code:
    <script>DateInput('dateoriginal', true, 'YYYY-MM-DD', '<?php $cStart; ?>')</script>
    $cEnd is the variable for the corresponding field, and its a MSSQL database and the datetime field is set as YYYY-MM-DD

    I just tried also to echo the date out of the database and it wont do it, so do I need to sort of get the code right first to handle a date before displaying it.
    This is how my PHP looks and im using a MSSQL database.

    PHP Code:
    $queryEdit="select * from CSF_Intranet where Contract_Number=$customer_Number";
    $rowsEdit sqlsrv_query($conn$queryEdit);
    while (
    $rows sqlsrv_fetch_array($rowsEditSQLSRV_FETCH_ASSOC)) {
        
    $cStart=$rows["Contract_Start"]; 

    Cheers
    Last edited by multichild; 04-27-2012 at 02:05 PM.

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    243
    Thanks
    1
    Thanked 18 Times in 18 Posts

    Default

    I think you have the right concept. I have done this with the same js code you are using but it's been a while. In your example above you forgot to echo $cStart in the js code, so that may be part of it. Here is what I used
    PHP Code:
    <script type="text/javascript">DateInput('sp_start', false<?php if(isset($sp_start)){if (!empty($sp_start)){echo ",'YYYY-MM-DD', '$sp_start'";}}?>)</script>

  3. #3
    Join Date
    Jan 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi there, thank you for getting back to me.

    Is it just the case that you can just assign a value to a variable as below when pulling a date down from the database:
    PHP Code:
    $queryEdit="select * from CSF_Intranet where Contract_Number=$customer_Number";
        
    $rowsEdit sqlsrv_query($conn$queryEdit);
        while (
    $rows sqlsrv_fetch_array($rowsEditSQLSRV_FETCH_ASSOC)) {
    $cStart=$rows["Contract_Start"];} 
    Or do I need to add extra code to it to allow it to recognise its a date and not just simply a number or a character.

    The reason Im asking is because when I am in the stock update bit it doesnt display properly until I changed 'false' to true, and then in the update/edit part there is a problem as the date update widget doesnt show and the rest of the page doesnt display either.

    PHP Code:
    <script type="text/javascript">DateInput('dateoriginal', true<?php if(isset($cStart)){if (!empty($cStart)){echo ",'YYYY-MM-DD', '$cStart'";}}?>)</script>
    Ive had a go and Im wondering if this is it, but it messes the whole thing up then and the date changeer doesnt display.

    PHP Code:
    $cStart=date_format($rows['Contract_Start'],'Y/M/D'); 


    Thanks
    Last edited by multichild; 04-30-2012 at 11:03 AM.

  4. #4
    Join Date
    Jan 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OK I think I can see an obvious problem here and not sure how to fix it, which might be why its not displaying.

    Here is my code to start off with as it is now:

    PHP Code:
    $queryEdit="select * from CSF_Intranet where Contract_Number=$customer_Number";
        
    $rowsEdit sqlsrv_query($conn$queryEdit);
        while (
    $rows sqlsrv_fetch_array($rowsEditSQLSRV_FETCH_ASSOC)) {
        
    $cStart=date_format($rows["Contract_Start"],"M/D/Y"); 
    Which seems to work fine.

    Then I have this:

    PHP Code:
    <script type="text/javascript">DateInput('dateoriginal', true<?php if(isset($cStart)){if (!empty($cStart)){echo ",'YYYY-MM-DD', '$cStart'";}}?>)</script>
    I then echo'd out $cStart and this is what I got.

    Code:
    Jan/Thu/2012
    When what I need is the week day bit to be a number date as it is the database. Not sure how Im going ot get around this.

  5. #5
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    243
    Thanks
    1
    Thanked 18 Times in 18 Posts

    Default

    What does this look like if you echo it - $rows["Contract_Start"]

  6. #6
    Join Date
    Jan 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi fastsol1,

    I tried that and all it does is stop the whole page from working if I put it in the isset script as shown, or it stops the rest of the page loading if I put it where in its place in the form.

  7. #7
    Join Date
    Jan 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OK I have made a little bit of progress.

    I have changed the way I grab the date from the database to below:

    PHP Code:
    $cStart date("m-d-Y"strtotime(Contract_Start));
    echo 
    $cStart
    And echo'd it out and it came back with this below:

    01-01-1970

    But the date in the database is this:

    2012-01-12

    But another bit of progress is that the date calendar is also working but with the wrong date above 70-01-01, and for that I'm using the code below:

    Code:
    <script type="text/javascript">DateInput('dateoriginal', false<?php if(isset($cStart)){if (!empty($cStart)){echo ",'MM-DD-YYYY', '$cStart'";}}?>)</script>
    The date calendar is displaying:

    Jan 1 1970

    So I'm not sure whats going on here.

    Getting there I think.
    Last edited by multichild; 05-01-2012 at 03:06 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •