Tenaciousmug Posted September 22, 2010 Share Posted September 22, 2010 I can't figure out how to select something from the database that is under today's date. This is what I have: if($row['date'] == ".date('Y-m-d').' 00:00:00'."' AND date < '".date('Y-m-d').' 23:59:59'.") Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/214107-selecting-todays-date-from-database/ Share on other sites More sharing options...
taquitosensei Posted September 22, 2010 Share Posted September 22, 2010 You would do this in your select statement select fields from table where datefield <= now() Quote Link to comment https://forums.phpfreaks.com/topic/214107-selecting-todays-date-from-database/#findComment-1114111 Share on other sites More sharing options...
Tenaciousmug Posted September 22, 2010 Author Share Posted September 22, 2010 Here is my select statement: $sql = "SELECT date FROM sixdice WHERE username='$username'"; I'm trying to select the date from the game I'm creating to see if that user already rolled the dice today. Ok this is what I have: <?php include("haha.php"); $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase); $sql = "SELECT date FROM sixdice WHERE username='$username'"; $result = mysqli_query($cxn,$sql) or die("Couldnt find username"); $row = mysqli_fetch_array($result); if($row['date'] == now()); { echo "<br><br><form action='sixdice.php?roll' method='post'> <input type='submit' name='continuesix' value='Continue Game' /> </form>"; }else { echo "<br><br><form action='sixdice.php?roll' method='post'> <input type='submit' name='playsix' value='Play!' /> </form>"; }?> It's giving me this error: " Parse error: syntax error, unexpected T_ELSE in /home2/asterock/public_html/sixdice.php on line 25" Which is this line: }else EDIT Also, doesn't the now() function select the time as well? I only want to select today's DATE. Not the time too. Quote Link to comment https://forums.phpfreaks.com/topic/214107-selecting-todays-date-from-database/#findComment-1114112 Share on other sites More sharing options...
Tenaciousmug Posted September 22, 2010 Author Share Posted September 22, 2010 Nevermind, figured it out. Thanks though! Quote Link to comment https://forums.phpfreaks.com/topic/214107-selecting-todays-date-from-database/#findComment-1114124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.