0

I'm having an problem with my PHP event calendar. I allready Searched but can't find an solution. In particular I have an mysql database with an datetime field. In my PHP page I have an for loop to get the events for that date. And need to search with an select query in my database in the datetime field. I only need to have to search in date (not with time). Problem is that I can't get the right value for my search query? I've tried with converting strtotime, etc... but Notting seams to work!? I have similar questions read on this forum but didn't find an answer. Thx for the help allready. Here is my code:

     <?php 
      For ($i=1; $daycount; $i++){. 
      $date = $showmonth.'-'.$i.'-'.$showyear;
      $query = mysqli_query($conn, "SELECT id FROM tblname WHERE date="'.$date.'");
      ...

Additional info: in my mysql database I have 3 fields id (int), events (varchar), date (datetime). I have an separeted form dat post the content into the database. Here I work with mktime and this works fine. But on my showcalender.php page I have build with JavaScript, css an calendar. I used before (in an previous version) an field (in my mysql db) the type varchar (instead of datetime)to save my date and than it work wel to collect and get the events list up in my showcalender.php. But I changed the field (in mysql) date in an datetime because I want to calculate with it. Probleem is that I can not convert my $date correct now to collect my events.

WFender
  • 13
  • 3
  • Could you post the description of the DB table? And sample data from that DB table – Dragos Dec 02 '16 at 15:39
  • 1
    What is that `*showmonth` ? that's no valid PHP structure – Dragos Dec 02 '16 at 15:40
  • [strtotime()](http://php.net/manual/en/function.strtotime.php) and [date()](http://php.net/manual/en/function.date.php) would also help – Dragos Dec 02 '16 at 15:44
  • 1
    since you had at least 3 syntax errors in those 3 lines i can give you a tip for the future. before you search online for a solution to why your code does not work, look at your code and find all potential syntax errors. that will save you lots of time – kscherrer Dec 02 '16 at 15:47
  • @Cashbee Well it will save us a lot of time anyway! – RiggsFolly Dec 02 '16 at 15:48
  • 1
    **In future** Add [error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Dec 02 '16 at 15:51
  • 1
    Or familiarise yourself with where the PHP Error log is on your system and when something does not work, take a look at it – RiggsFolly Dec 02 '16 at 15:52

1 Answers1

1

You are missing a " before SELECT and as its in double quotes you can use $data inside them and it will get expanded.

Also *showmonth should probably be $showmonth

Also the $++ in the for loop should probably be $i++

For ($i=1; $daycount; $i++){
    $date = $showmonth.'-'.$i.'-'.$showyear;

    $query = mysqli_query($conn, "SELECT id FROM tblname WHERE date='$date'");

As the date format you are building is not a standard YYY-MM-DD MYSQL DATETIME column datatype, Should we assume you have stored these dates as a VARCHAR or similiar?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149