0

I have a php script that checks every Sunday of the week and displays data on that day.

Users can change their value for that day to "Yes" or "No'.

I want to add a possibility that the users can't change their choice after every Thursday at 23:59 before that sunday.

I only want the first Sunday not to be editable. Since this all is in a loop that shows every Sunday until 11 Sundays in the future. I need to find a way to only do this for the first Sunday.

$datum_gisteren = new datetime('yesterday');
echo '<tr>';
echo '<td bgcolor="#3c741a" style="color:#FFFFFF;">&nbsp;'.$current_user->first_name.''.' '.''.$current_user->last_name.'</td>
<form action="" method="post">';
for ($i=0; $i<=11; $i++){
    $date_modified = $datum_gisteren->modify('next sunday')->format('d-m-y');
    $datum = get_the_author_meta( $date_modified, $current_user->ID );
    $time = '23:59'; 
    if(date('l') === 'Thursday' && date('H:i') >= $time && $date_modified === '06-09-15') {
        echo '<td>
        <select class="form-field" id="'.$date_modified.'" name="'.$date_modified.'">
        '.(($datum == '1') ? '<option value="1" selected disabled="disabled">Nee</option>' : '').'
        '.(($datum == '2') ? '<option value="2" selected disabled="disabled">Ja</option>' : '').' 
        </select></td>';
    }else{
        echo '<td>
        <select class="form-field" id="'.$date_modified.'" name="'.$date_modified.'">
        <option value="1" '.(($datum == '1') ? 'selected' : '').' >Nee</option>
        <option value="2" '.(($datum == '2') ? 'selected' : '').' >Ja</option>
        </select></td>';                        
    }
}   

Most of the work is done (I believe) but as you can see. The $date_modified in the first if-statement is "hardcoded" (06-09-15).

I want this value to be the first next sunday. But since this is in the loop it showed every Sunday for 11 times.

How can I set this Sunday once?

Hope it makes sense!!!

1
  • Not related to your question, but you should consider separatingpresentation from content (that is, don't mix inline CSS into your HTML). Commented Aug 31, 2015 at 13:25

1 Answer 1

1

You can keep additional variable for it:

$j = 0;

for ($i=0; $i<=11; $i++){
    $date_modified = $datum_gisteren->modify('next sunday')->format('d-m-y');
    $datum = get_the_author_meta( $date_modified, $current_user->ID );
    $time = '23:59'; 
    if(date('l') === 'Thursday' && date('H:i') >= $time && $j === 0) {
        $j++;
        echo '<td>
        <select class="form-field" id="'.$date_modified.'" name="'.$date_modified.'">
        '.(($datum == '1') ? '<option value="1" selected disabled="disabled">Nee</option>' : '').'
        '.(($datum == '2') ? '<option value="2" selected disabled="disabled">Ja</option>' : '').' 
        </select></td>';
    }else{
        echo '<td>
        <select class="form-field" id="'.$date_modified.'" name="'.$date_modified.'">
        <option value="1" '.(($datum == '1') ? 'selected' : '').' >Nee</option>
        <option value="2" '.(($datum == '2') ? 'selected' : '').' >Ja</option>
        </select></td>';                        
    }
} 

but will be good to segregate php logic from front.

Thanks.

Sign up to request clarification or add additional context in comments.

1 Comment

Thats pretty simple and genius. Thnx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.