News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Interesting PHP IF statement... need help, ty.

Started by MoreBloodWine, March 10, 2018, 04:37:03 PM

Previous topic - Next topic

MoreBloodWine

Not sure where to begin with this one, dont do mixes of date, time etc very well.

Anyway.... here's the script I'm after.

This is to be a weekly thing...

If the time is between 11:30pm Sat && 12:30am Sun., show THIS else show THAT.
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


Shambles

Here's a simple step-by-step that you should be able to understand:

$dayOfWeek = substr(date('W'),0,1);
$timeNow = time();
$halfHour = 1800;

$todaySat1 = strtotime('today 23:30:00');
$todaySat2 = $todaySat1 + $halfHour;

$todaySun1 = strtotime('today 00:00:00');
$todaySun2 = $todaySun1 + $halfHour;

if (
   ($dayOfWeek == '6' && ($todaySat1 >= $timeNow && $timeNow <= $todaySat2)) ||
   ($dayOfWeek == '0' && ($todaySun1 >= $timeNow && $timeNow <= $todaySun2))
   )
{echo 'show THIS';} else {echo 'show THAT';}

MoreBloodWine

#2
Quote from: Shambles on March 11, 2018, 07:08:02 AM
Here's a simple step-by-step that you should be able to understand:

$dayOfWeek = substr(date('W'),0,1);
$timeNow = time();
$halfHour = 1800;

$todaySat1 = strtotime('today 23:30:00');
$todaySat2 = $todaySat1 + $halfHour;

$todaySun1 = strtotime('today 00:00:00');
$todaySun2 = $todaySun1 + $halfHour;

if (
   ($dayOfWeek == '6' && ($todaySat1 >= $timeNow && $timeNow <= $todaySat2)) ||
   ($dayOfWeek == '0' && ($todaySun1 >= $timeNow && $timeNow <= $todaySun2))
   )
{echo 'show THIS';} else {echo 'show THAT';}

Ty. does the echo change any if I want to use HTML in it ?

Ex (line 47 - 51).
<form id='myform' method='post' action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>'>
46 <img border="0" src="arrow.gif" width="27" height="16"><img border="0" src="arrow.gif" width="27" height="16"><img border="0" src="arrow.gif" width="27" height="16"    >
47
48 <?php
 49         THIS 
= <input type='text' name='address' size='50' maxlength='60' /> <input type='submit' name='submit' value='Submit' />

THAT Lotto disabled pending drawingwill return 12:30am EST/EDT !
?>

51
52 </form>
53 <script>document.getElementById('myform').style.display = 'block';</script>
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


MoreBloodWine

Doesn't seem to be showing the input field of the form...

Thoughts ?

45 <form id='myform' method='post' action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>'>
46 <img border="0" src="arrow.gif" width="27" height="16"><img border="0" src="arrow.gif" width="27" height="16"><img border="0" src="arrow.gif" width="27" height="16"    >
47
48 <?php
 49         $dayOfWeek 
substr(date('W'),0,1);
 
50         $timeNow time();
 
51         $halfHour 1800;
 
52
 53         $todaySat1 
strtotime('today 23:30:00');
 
54         $todaySat2 $todaySat1 $halfHour;
 
55
 56         $todaySun1 
strtotime('today 00:00:00');
 
57         $todaySun2 $todaySun1 $halfHour;
 
58
 59         
if (
 
60            ($dayOfWeek == '6' && ($todaySat1 >= $timeNow && $timeNow <= $todaySat2)) ||
 
61            ($dayOfWeek == '0' && ($todaySun1 >= $timeNow && $timeNow <= $todaySun2))
 
62          )
 
63         {
 
64                 echo 'Lotto disabled pending drawing, will return 12:30am EST/EDT !';
 
65         } else {
 
66                 echo "x<input type='text' name='address' size='50' maxlength='60' /> <input type='submit' name='submit' value='Submit' />";
 
67         }
 
68 ?>

69
70 </form>
71 <script>document.getElementById('myform').style.display = 'block';</script>
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


MoreBloodWine

@Shambles: I know it might not seem like much but if you could please help me figure this out, I can Venmo you like $5 ?

Ty.
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


Shambles

Sorry buddy. I can only provide the requested timeframe algorithm. I know nothing about forms.

I did notice that your <img> tags aren't closed though...

MoreBloodWine

Quote from: Shambles on March 16, 2018, 04:17:27 AM
Sorry buddy. I can only provide the requested timeframe algorithm. I know nothing about forms.

I did notice that your <img> tags aren't closed though...
Thx, anyone ?
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


MoreBloodWine

BTW, here's the whole page code (it's a template file which is part of a larger picture) which when running properly should look like this: http://spend-ur-bits.com/index.php?page=btc_lottery

The x next to the echo with the input is just used to see if I could get the x to show. But I got nothing...

<div align="center">

        <table border="0" width="615" id="table5" style="background-color: rgb(39,43,48); color: rgb(200,200,200);">
                <tr>
                        <td>
                        </td>
                        <td width="536" align="left">
                        <center><span id="countdown" style="font-size: 20; font-weight:bold; color: rgb(200,200,200);"></span></center>
                        <p style="color: rgb(200,200,200);"><strong>Here's how you play: </strong><img src="point_here_animated.gif" width="66" height="29"></p><span s$
<ol>
    <li>Enter your {COINTYPEFULL} Wallet address for winnings to be sent to, below.</li>
    <li>Send <span style="color: #FE2E64;">{COST} {COINTYPEABBR}</span> to the wallet address given to you on the next page.</li>
    <li>For every {COST} {COINTYPEABBR} you send, you will be entered <span style="color: #FE2E64;">once</span> into the drawing.</li>
                <ul>
                        <li>(ex. Sending <script>document.write(total);</script> will net you three entries for a greater chance of winning.)</li>
                </ul>
        <li>You can play as many times as you like.</li>
        <li>You can buy as many tickets as you like.</li>
    <li>Every <span style="color: #FE2E64;">Sunday</span> at <span style="color: #FE2E64;">{DRAWTIME}</span>, one winner will be randomly selected.</li>
<!--            <ul>
                        <li>
                                <span id="countdown" style="font-size: 20; font-weight:bold;"></span>
                        </li>
                </ul>-->
    <li>If you are selected, {WINNERPERCENTAGE}% of the Lottery Pool will be sent to you.</li>
        <li>The other {OWNERPERCENTAGE}% goes to supporting the {SITENAME} lottery.</li>
        <li><span style="color: #FE2E64;">Remember</span> - You have to be in it to win it!</li>
        <li>Enjoy the lotto ? Then please consider a donation to help sustain the server.</li>
                <ul>
                        <li>
                        <span style="color: #FE2E64;">Donation Address:</span> EaMteK2XNFTqj32YmgaXicaXGG2rkgffso
                        </li>
                </ul>
</ol>
</span>
<!-- IF FATAL_ERROR -->
                        <strong><span style='color:red'>FATAL ERROR:</span></strong> {FATALERROR}
                        <!-- ENDIF -->
<p style="color: rgb(200,200,200);"><strong>If you'd like to play, please enter your {COINTYPEFULL} Wallet address below:</strong></p>

<!-- IF ERROR -->
<p><strong><span style='color:red'>ERROR:</span></strong> {ERROR} Please try again.</p>
<!-- ENDIF -->

<form id='myform' method='post' action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>'>
<img border="0" src="arrow.gif" width="27" height="16"><img border="0" src="arrow.gif" width="27" height="16"><img border="0" src="arrow.gif" width="27" height="16"  $

<?php
         $dayOfWeek 
substr(date('W'),0,1);
         
$timeNow time();
         
$halfHour 1800;

         
$todaySat1 strtotime('today 23:30:00');
         
$todaySat2 $todaySat1 $halfHour;

         
$todaySun1 strtotime('today 00:00:00');
         
$todaySun2 $todaySun1 $halfHour;

         if (
            (
$dayOfWeek == '6' && ($todaySat1 >= $timeNow && $timeNow <= $todaySat2)) ||
            (
$dayOfWeek == '0' && ($todaySun1 >= $timeNow && $timeNow <= $todaySun2))
          )
         {
                 echo 
'Lotto disabled pending drawing, will return 12:30am EST/EDT !';
         } else {
                 echo 
"x<input type='text' name='address' size='50' maxlength='60' /> <input type='submit' name='submit' value='Submit' />";
         }
?>


</form>
<script>document.getElementById('myform').style.display = 'block';</script>

<script>document.getElementById('myform').style.display = 'block';</script>

<noscript>
It appears you have JavaScript turned <b><font color="#FF0000">OFF</font></b>, please turn it on if you wish to participate.<br />
</noscript><br>
                        </td>                        <td>
                        </td>
                </tr>
        </table>
</div>
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


Sir Osis of Liver

Play with this -



<?php

// If the time is between 11:30pm Sat && 12:30am Sun., show THIS else show THAT.

$day date("l");
$hour date("H");
$min date("i");

//$day = 'Sunday';
//$hour = 00;
//$min = 32;

echo 'Day - ' $day '<br >';
echo 
'Hour - ' $hour '<br >';
echo 
'Min - ' $min '<br >';

if ((
$day == 'Saturday' && $hour == 11 && $min 29) || ($day == 'Sunday' && $hour == 00 && $min 31))
echo 'THIS';
else
echo 'THAT';

?>



Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

MoreBloodWine

Same as Shambles code, field doesn't show. Has to be a form issue because if I use the code by itself, yours or his, it works: http://spend-ur-bits.com/lottery_egc/templates/test.php

His code top, yours bottom.

<form id='myform' method='post' action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>'>
<img border="0" src="arrow.gif" width="27" height="16"><img border="0" src="arrow.gif" width="27" height="16"><img border="0" src="arrow.gif" width="27" height="16"   $

<?php

// If the time is between 11:30pm Sat && 12:30am Sun., show THIS else show THAT.

$day date("l");
$hour date("H");
$min date("i");

//$day = 'Sunday';
//$hour = 00;
//$min = 32;

//echo 'Day - ' . $day . '<br >';
//echo 'Hour - ' . $hour . '<br >';
//echo 'Min - ' . $min . '<br >';

if (($day == 'Saturday' && $hour == 11 && $min 29) || ($day == 'Sunday' && $hour == 00 && $min 31))
        echo 
'Lotto disabled pending drawing, will return 12:30am EST/EDT !';
else
        echo 
'<input type='text' name='address' size='50' maxlength='60' /> <input type='submit' name='submit' value='Submit' />';

?>


</form>
<script>document.getElementById('myform').style.display = 'block';</script>

<noscript>
It appears you have JavaScript turned <b><font color="#FF0000">OFF</font></b>, please turn it on if you wish to participate.<br />
</noscript>
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


MoreBloodWine

Problem solved, Just had to do the second ech as such.

echo ' ?>

my html...

<?php '; ?>
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


MoreBloodWine

Just so I don't butcher this more than I already probably have.

I changed my outlying code a bit and now need this to be between 12am sun to 1am sun.

if (($day == 'Sunday' && $hour == 00 && $min = 00) || ($day == 'Sunday' && $hour == 01 && $min < 01))

Quote from: Sir Osis of Liver on March 17, 2018, 01:04:03 AM
Play with this -



<?php

// If the time is between 11:30pm Sat && 12:30am Sun., show THIS else show THAT.

$day date("l");
$hour date("H");
$min date("i");

//$day = 'Sunday';
//$hour = 00;
//$min = 32;

echo 'Day - ' $day '<br >';
echo 
'Hour - ' $hour '<br >';
echo 
'Min - ' $min '<br >';

if ((
$day == 'Saturday' && $hour == 11 && $min 29) || ($day == 'Sunday' && $hour == 00 && $min 31))
echo 'THIS';
else
echo 'THAT';

?>



Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


Sir Osis of Liver

You should only need this -



     if ($day == 'Sunday' && $hour < 01)



That will cover you from 00:00 - 00.59 Sunday.

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

MoreBloodWine

Quote from: Sir Osis of Liver on March 17, 2018, 11:51:57 PM
You should only need this -



     if ($day == 'Sunday' && $hour < 01)



That will cover you from 00:00 - 00.59 Sunday.
Thx. Will give it a whirl.
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


MoreBloodWine

Changed it to 02, to test. Still shows the input field ;-/

<?php
 53
 54 
// If the time is between 11:30pm Sat && 12:30am Sun., show THIS else show THAT.
 
55
 56 $day 
date("l");
 
57 $hour date("H");
 
58 $min date("i");
 
59
 60 
// $day = 'Sunday';
 
61 // $hour = 00;
 
62 // $min = 32;
 
63
 64 
// echo 'Day - ' . $day . '<br >';
 
65 // echo 'Hour - ' . $hour . '<br >';
 
66 // echo 'Min - ' . $min . '<br >';
 
67
 68 
// if (($day == 'Sunday' && $hour == 00 && $min = 00) || ($day == 'Sunday' && $hour == 01 && $min < 01))
 
69 if ($day == 'Sunday' && $hour 02)
 
70         echo 'Lotto disabled pending 12:30am draw time, will return 1am EST/EDT !';
 
71 else
 
72         echo '?>

73                 <input type='text' name='address' size='50' maxlength='60' /> <input type='submit' name='submit' value='Submit' />
74 <?php ';
 75
 76 ?>
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


Sir Osis of Liver

If you uncomment this -



echo 'Day - ' . $day . '<br >';
echo 'Hour - ' . $hour . '<br >';
echo 'Min - ' . $min . '<br >';



it will display current day/time.

If you uncomment this -



$day = 'Sunday';
$hour = 00;
$min = 32;



you can set any day/time for test purposes.

Have you tried that?
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Advertisement: