How can i print all results from table with a specific date?

Hello.

I have made a form thats stores i an databse, with 2 fields.
{name} and {date e.g. mm–dd–yyyy}

i have to get print all the names that has a date from the past monday to the next monday.
All the other results in the table should be in the table, but not shown on the html page.
right now i am using:
[php]<?php
$con = mysql_connect(“host”,“username”,“password”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“database”, $con);

$result = mysql_query(“SELECT * FROM taple”);

while($row = mysql_fetch_array($result))
{
echo $row[‘navn’];
}

mysql_close($con);
?>[/php]

This is easy if you are using a proper column type for your date. Show the table structure.

http://www.humlebaekbadminton.dk/1.png
http://www.humlebaekbadminton.dk/2.png

You should be able to simply use BETWEEN e.g.

SELECT * FROM `table` WHERE `date_field` BETWEEN '2012-10-29' AND '2012-11-05';

hello.

First of all. Thank you for helping. I understand your code. but the problem is, that i shouldn’t change the php code every week. i therefor need a code, whitch automagicly changes the days to the next monday when the other one is past.

you can always use variable with Matt’s query

[php]
//this is just an example you need get the date from another source dynamically.
$date1 = ‘2012-10-29’;
$date2 = ‘2012-11-01’;

SELECT * FROM table WHERE date_field BETWEEN ‘$date1’ AND ‘$date2’;
[/php]

There are many PHP date/time functions that can be used to automatically define Monday to Monday range. If you make an effort I will help.

Sponsor our Newsletter | Privacy Policy | Terms of Service