[SOLVED] Using Select boxes to input date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

I thought this would be the correct thing to do:

Code: Select all

WHERE datecontactagain LIKE '$var1."-".$var3."-".$var2;'";
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

you've already done that at the begining of the script...no need to do it again, just use the other variable
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

this will compare the variables entered wont it?

Code: Select all

WHERE datecontactagain LIKE '$var1."-".$var3."-".$var2;'";
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

before i pull my hair out

here...

Code: Select all

WHERE datecontactagain LIKE '$datecontactagain'";
:roll:
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

sorry pimp, I worked that out didnt get the chance to get back to you, I havent tested it yet one sec, damn Ive gotto say thank you for the way in which you answer my questions, Its so much more challenging then just giving the answers. only thing is im worried that people wont have the time to explain thanks Mark appreciate it.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Mark,

I have added a new record with the contact again date set to todays date.
25th of May 2005

When I search the database for this date my table displays fine but it doesnt find any results.

heres my code:

Code: Select all

$var1 = $_POST["datecontactagain_Year"];
$var2 = $_POST["datecontactagain_Day"];
$var3 = $_POST["datecontactagain_Month"];  
$datecontactagain = $var1."-".$var3."-".$var2;

foreach($HTTP_POST_VARS as $varname => $value)
        $formVars[$varname]=$value;

$query = "SELECT 
		o.org_id,o.web_url,
		p.person_id,p.org_id,p.salutation,p.firstname,p.surname,
		p.organisation,p.role,p.address1,p.address2,p.city,
		p.postcode,p.telephone,p.mobile,p.fax,p.dateoflastcontact,
		p.datecontactagain,p.notes,p.email, 


		DATE_FORMAT(dateoflastcontact, '%M/%Y') 
		AS dateoflastcontact, DATE_FORMAT(datecontactagain, '%M/%Y') 
		AS datecontactagain 

		
		FROM people p LEFT JOIN organisations o
     		ON o.org_id = p.org_id

		WHERE datecontactagain LIKE '$datecontactagain'";


$result = mysql_query($query);
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

it is becuase you have reformatted the date in the query ont his line

Code: Select all

DATE_FORMAT(dateoflastcontact, '%M/%Y') AS dateoflastcontact, DATE_FORMAT(datecontactagain, '%M/%Y') AS datecontactagain
i would have done this

Code: Select all

DATE_FORMAT(dateoflastcontact, '%M/%Y') AS dateoflastcontact_formatted, DATE_FORMAT(datecontactagain, '%M/%Y') AS datecontactagain_formatted
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

thanks tried that as well and just to make doubly sure added a new record with todays date then searched todays date again and still no results
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

change WHERE to = in this line

Code: Select all

WHERE datecontactagain LIKE '$datecontactagain'";
(still with the previous changes i told ya)
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

do you mean change the LIKE TO =?
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

sorry, obviously you mean that, one sec
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

mohson wrote:do you mean change the LIKE TO =?
whopps, that is what i meant :lol:
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Yep Mark that has worked fine brilliant, only thing is I had to remove the '_formatted' because its displayling the date like this '2005-05-25' so I changed back to before and it works fine.

I think Ill give you a break now, thanks agin MENTOR PIMPSTER.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Cool :D

lesson over...for now
Post Reply