Jump to content

Mysql+Php Date Problem?


falca

Recommended Posts

I am trying to edit an announcement site.I dont know more about Php and Mysql.I want to create 2 columns named "start" and "finish" on Mysql and on my anouncment page i will have 2 combobox and will take the date from "start" and "finish" column.When user choose a date between "start" and "finish" it will show the announcement between this dates.Can someone help me and can someone give his/her messenger address to help me?

Link to comment
https://forums.phpfreaks.com/topic/204484-mysqlphp-date-problem/
Share on other sites

Can you explain more about your date control in your html page? Two combo box? How your date format looks like?

From what I've understand, you have a page that need to display the announcement and also allowed user to filter the announcement by the date range (between).

Try specify your question.

I dont know how to say in php or web programming for combobox.For example think about that i have a page named "announcement.php".This page must have 2 combobox.These comboboxes must take the date information from Mysql "start" and "finish" columns.For example when user choose a date from combobx1 14.03.2003 and choose from a date combobox2 it must appear my anouncement which is between these 2 dates.I dont know it is clear or not

I'll give u a brief example. In your announcement.php, try use a textbox instead of combobox. Let's name it date_1 and date_2.

Use a form to wrap these two textbox:

<form name="search" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">

  <input type="text" name="date_1" size="15" />

  <input type="text" name="date_2" size="15" />

  <input type="submit" value="Search" />

</form>

I won't teach u on creating database table. I'll assumed you have two column of DATE type in your MySQL database.

 

On top of your announcement.php, put this:

<?php

// Make your db connection first...

 

if (isset($_GET['date_1']) && isset($_GET['date_2'])) {

  $sql = "SELECT * FROM `announcement` WHERE `start` < '{$_GET['date_1']}' AND `end` > '{$_GET['date_2']}';";

  $qry = mysql_query($sql) or die(mysql_error());

}

?>

<html> (your html code goes here)....

 

Once you got that, enter the correct date in the two textbox: 2010-6-12 and 2010-6-13.

This is POC. You need more modification and read more tutorial on PHP MYSQL:

http://www.tizag.com/mysqlTutorial/

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.