Jump to content

[SOLVED] how to select current month...


new_php85

Recommended Posts

hai...

 

i have problem to select current month...

 

this is my example coding for select current month. why its not appear.

 

$current_month = date(Y-m);


$query_cm = "SELECT * FROM cldr WHERE startDate like '$current_month-%' order by startDate desc";
$result_cm = mysql_query($query_cm) or die('Query failed. ' . mysql_error());

<form name="current_month" id="current_month" method = "post">
  <table bordercolor="#EEF8D6" border="1" cellpadding="3" cellspacing="0" align="center">

    <th width="14"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">No.</font></th>
    <th width="105"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Name</font></th>
    <th width="329"><div align="left"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Location</font></div></th>
    <th width="40"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Start 
      Date</font></th>
    <th width="40"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">End 
      Date</font></th>
    <th width="40"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Edit</font></th>
    <th width="46"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Delete</font></th>
    <?php
$c=1;
while($row = mysql_fetch_assoc($result_cm))
{
?>
    <tr> 
      <td><div align="center"><?php echo $c?></div>
      <td><?php echo $row['staffKcc']?></td>
      <td><?php echo $row['location']?></td>
      <td><?php echo $row['startDate']?></td>
      <td><?php echo $row['endDate']?></td>
      <td><div align="center"><a href="editEvent.php?id=<?php echo $row['id']?>">Edit</a></div></td>
      <td><div align="center"><a href="deleteEvent.php?id=<?php echo $row['id']?>">Delete</a></div></td>
    </tr>
    <?php
$c++; 
} 
?>
  </table>
</form>

 

plz help me...

 

Link to comment
https://forums.phpfreaks.com/topic/131292-solved-how-to-select-current-month/
Share on other sites

$query_cm = "SELECT * FROM cldr WHERE startDate like '$current_month-%' order by startDate desc";

 

 

what do the startDate values look like in your database?

 

right now $current_month = 2008-11

 

example in database: startDate = '2008-11-04'

 

i know if i put date(Y-m) it will be 2008-11

 

that's why in query i put % for day to neglect the value...

 

is it wrong??

corbin i got what u said. it should like this  $current_month = date("Y-m"); thank you ya...

 

$current_month = date(Y-m);

 

should be $current_month = date("Y-m");

 

Y-m isn't a constant, so it should be in quotes.

 

 

 

What is the datatype of startDate?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.