Welcome Guest, Not a member yet? Register   Sign In
Restricting input by language and date math
#1

[eluser]ajknodel[/eluser]
I have a website that requires that all input be in English, but the nature of it means that some might come along and use Korean or Japanese input. Is there any way to make sure input provided is in English? I've successfully been able to input Korean in to the database and I don't want that to work for various reasons.

Something else that I would like to know about is how to perform queries using Active Record that will filter results based on date ranges. It seems to me that I need to use MySQL commands (since that's my database), but how do you issue MySQL commands using Active Record? Is there documentation somewhere about this issue?

If I have to switch to a different type of database query, could I generate results based on search criteria using a stored procedure or generate a query based on an already-existing data set? I'm a little lost here so any pointers would be helpful.

Thanks. Love the framework. It's been very helpful so far!

edit: forgot one thing: I want to input dates with minutes and sometimes seconds but I haven't figured out the mdate() format for that.

Code:
$datestring = "%Y%m%d";
works, but I'd like more accuracy. Thanks again!
#2

[eluser]Sbioko[/eluser]
You can restrict inputing by other languages using regex:
Code:
if(!preg_match('/([a-z],[A-Z])/', $input)) // Maybe this regex wrong, but I gived an example. Also, try /[a-z]/i
{
   echo 'Only english!';
}
#3

[eluser]ajknodel[/eluser]
[quote author="Demedes" date="1262629551"]You can restrict inputing by other languages using regex:
Code:
if(!preg_match('/([a-z],[A-Z])/', $input)) // Maybe this regex wrong, but I gived an example. Also, try /[a-z]/i
{
   echo 'Only english!';
}
[/quote]Thanks. I figured I might have to do something like this. I could still use some pointers on date math in SQL queries. All my searches have been unfruitful on that subject.
#4

[eluser]Sbioko[/eluser]
And about dates. This is easy. You can use native php date function, or use codeigniter's date helper. Or I didn't understand you?
#5

[eluser]ajknodel[/eluser]
[quote author="Demedes" date="1262696445"]And about dates. This is easy. You can use native php date function, or use codeigniter's date helper. Or I didn't understand you?[/quote]Well, there's two issues:
1) (and very slightly less important) is the issue of the mdate string format to get minutes and seconds.
2) (and slightly more important) is the issue of selecting items in a database based on a date range. If there is a way to do this I am completely unaware. Do you think you could be just a bit specific here? I could really use the help Smile
#6

[eluser]Sbioko[/eluser]
you can use human_to_unix function from the date helper to translate date to timestamp and do this query to select items in a database based on a date range:
Code:
SELECT * FROM items WHERE time<{$first_timestamp} AND time>{$second_timestamp}
.
Maybe I didn't understand you, because english is not my native language :-)
#7

[eluser]Fabdrol[/eluser]
[quote author="Demedes" date="1262717802"]you can use human_to_unix function from the date helper to translate date to timestamp and do this query to select items in a database based on a date range:
Code:
SELECT * FROM items WHERE time<{$first_timestamp} AND time>{$second_timestamp}
.
Maybe I didn't understand you, because english is not my native language :-)[/quote]

Demedes' solution works only if you use unix-style timestamps (in seconds from 1970-01-01), but mysql's datetime or date fields takes a slightly different approach.

To calculate with them, I'd select them as UNIX TIME's, like this:
Code:
SELECT UNIX_TIMESTAMP(datefield) FROM table WHERE id = "x";

It will return the datetimes as seconds since the UNIX epoch (1970-01-01 00:00:00) and thats perfect for calculations in php. (using php's native time functions)

cheers!




Theme © iAndrew 2016 - Forum software by © MyBB