Advertisement:

Author Topic: Interesting PHP IF statement... need help, ty.  (Read 2490 times)

Offline MoreBloodWine

  • SMF Hero
  • ******
  • Posts: 2,723
  • Gender: Male
  • ...
    • Uncharted 2: Among Thieves Stat Sig Generator
Interesting PHP IF statement... need help, ty.
« on: March 10, 2018, 04:37:03 PM »
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


Offline Sh@mbles

  • SMF Hero
  • ******
  • Posts: 4,968
  • Gender: Male
    • i30 Owners Club
Re: Interesting PHP IF statement... need help, ty.
« Reply #1 on: March 11, 2018, 07:08:02 AM »
Here's a simple step-by-step that you should be able to understand:

Code: [Select]
$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';}

Offline MoreBloodWine

  • SMF Hero
  • ******
  • Posts: 2,723
  • Gender: Male
  • ...
    • Uncharted 2: Among Thieves Stat Sig Generator
Re: Interesting PHP IF statement... need help, ty.
« Reply #2 on: March 11, 2018, 11:04:46 PM »
Here's a simple step-by-step that you should be able to understand:

Code: [Select]
$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).
Code: [Select]
<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>
« Last Edit: March 11, 2018, 11:40:19 PM by MoreBloodWine »
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


Offline MoreBloodWine

  • SMF Hero
  • ******
  • Posts: 2,723
  • Gender: Male
  • ...
    • Uncharted 2: Among Thieves Stat Sig Generator
Re: Interesting PHP IF statement... need help, ty.
« Reply #3 on: March 12, 2018, 02:11:30 AM »
Doesn't seem to be showing the input field of the form...

Thoughts ?

Code: [Select]
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


Offline MoreBloodWine

  • SMF Hero
  • ******
  • Posts: 2,723
  • Gender: Male
  • ...
    • Uncharted 2: Among Thieves Stat Sig Generator
Re: Interesting PHP IF statement... need help, ty.
« Reply #4 on: March 15, 2018, 09:02:45 PM »
@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


Offline Sh@mbles

  • SMF Hero
  • ******
  • Posts: 4,968
  • Gender: Male
    • i30 Owners Club
Re: Interesting PHP IF statement... need help, ty.
« Reply #5 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...

Offline MoreBloodWine

  • SMF Hero
  • ******
  • Posts: 2,723
  • Gender: Male
  • ...
    • Uncharted 2: Among Thieves Stat Sig Generator
Re: Interesting PHP IF statement... need help, ty.
« Reply #6 on: March 17, 2018, 12:12:45 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


Offline MoreBloodWine

  • SMF Hero
  • ******
  • Posts: 2,723
  • Gender: Male
  • ...
    • Uncharted 2: Among Thieves Stat Sig Generator
Re: Interesting PHP IF statement... need help, ty.
« Reply #7 on: March 17, 2018, 12:43:18 AM »
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...

Code: [Select]
<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


Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 8,403
  • Riding the endless highway in the sky.
Re: Interesting PHP IF statement... need help, ty.
« Reply #8 on: March 17, 2018, 01:04:03 AM »
Play with this -

Code: [Select]

<?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';

?>



Offline MoreBloodWine

  • SMF Hero
  • ******
  • Posts: 2,723
  • Gender: Male
  • ...
    • Uncharted 2: Among Thieves Stat Sig Generator
Re: Interesting PHP IF statement... need help, ty.
« Reply #9 on: March 17, 2018, 02:01:28 AM »
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.

Code: [Select]
<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


Offline MoreBloodWine

  • SMF Hero
  • ******
  • Posts: 2,723
  • Gender: Male
  • ...
    • Uncharted 2: Among Thieves Stat Sig Generator
Re: Interesting PHP IF statement... need help, ty.
« Reply #10 on: March 17, 2018, 06:34:49 PM »
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


Offline MoreBloodWine

  • SMF Hero
  • ******
  • Posts: 2,723
  • Gender: Male
  • ...
    • Uncharted 2: Among Thieves Stat Sig Generator
Re: Interesting PHP IF statement... need help, ty.
« Reply #11 on: March 17, 2018, 07:24:04 PM »
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))

Play with this -

Code: [Select]

<?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


Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 8,403
  • Riding the endless highway in the sky.
Re: Interesting PHP IF statement... need help, ty.
« Reply #12 on: March 17, 2018, 11:51:57 PM »
You should only need this -

Code: [Select]

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


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


Offline MoreBloodWine

  • SMF Hero
  • ******
  • Posts: 2,723
  • Gender: Male
  • ...
    • Uncharted 2: Among Thieves Stat Sig Generator
Re: Interesting PHP IF statement... need help, ty.
« Reply #13 on: March 18, 2018, 01:07:25 AM »
You should only need this -

Code: [Select]

     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


Offline MoreBloodWine

  • SMF Hero
  • ******
  • Posts: 2,723
  • Gender: Male
  • ...
    • Uncharted 2: Among Thieves Stat Sig Generator
Re: Interesting PHP IF statement... need help, ty.
« Reply #14 on: March 18, 2018, 01:22:11 AM »
Changed it to 02, to test. Still shows the input field ;-/

Code: [Select]
<?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


Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 8,403
  • Riding the endless highway in the sky.
Re: Interesting PHP IF statement... need help, ty.
« Reply #15 on: March 18, 2018, 04:37:26 PM »
If you uncomment this -

Code: [Select]

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


 it will display current day/time.

If you uncomment this -

Code: [Select]

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


 you can set any day/time for test purposes.

Have you tried that?