Ask a Question related to Dreamweaver AppDev, Design and Development.
-
goldstein #1
Wilcard character problem in PHP/MySQL
I have a mysql table with the field DT_DATESUB. Its a date field YYYY-MM-DD. I
have a search php page with a dropdown menu holding the YEARS by using 'SELECT
DISTINCT DATE_FORMAT(DT_DATESUB, '%Y') AS YEARS FROM tablename'. I also have a
static option in the same dropdown menu with an option 'All Years' and value
the wildcard character %. In the results page I have a recordset with the
following SQL 'SELECT * FROM tablename WHERE DATE_FORMAT(DT_DATESUB, '%Y') =
'year' '. (year = $_GET['year']) It works for the distinct values but for the %
value it returns nothing. Its something really simple about DATE_FORMAT but
what??Any ideas? Apache/2.0.53 (Win32) PHP/4.3.10
goldstein Guest
-
French character and MySQL
Hi, I have MySQL database that has some French fields and I when I display them in a cfm page, special character are not displayed properly. I... -
Forms, Character Encoding, and MySQL
Could someone help shed some light on the proper way to handle special characters within Flex forms. i.e. Someone types and em-dash or bullet in... -
Coldfusion MySQL Character Problems
Has anyone run across problems with MySQL outputing invalid characters with Coldfusion? I am having the following problem when trying to output... -
CF MX 7 and MySQL - problem with UTF-8 character set
Hello, I have problem with UTF-8 character support. I'm using ColdFusion MX 7 and MySQL 4.1.7. I need UTF-8 support because I'm using german... -
InDesign ME Character Problem! Character-Change by Printing or saving *.PS!
Hi everybody! I have some problems with ME Version. When i want to print a page with FARSI-Text in it, he changes one character! on screen he... -
David Powers #2
Re: Wilcard character problem in PHP/MySQL
goldstein wrote:
It's got nothing to do with DATE_FORMAT; it's your use of a wildcard> In the results page I have a recordset with the
> following SQL 'SELECT * FROM tablename WHERE DATE_FORMAT(DT_DATESUB, '%Y') =
> 'year' '. (year = $_GET['year']) It works for the distinct values but for the %
> value it returns nothing. Its something really simple about DATE_FORMAT but
> what?
that's incorrect SQL. Using = '%' will search for a literal percentage
sign. To use a wildcard, your SQL needs to use LIKE. Consequently, you
need two separate SQL queries for your results page.
The most appropriate solution would be to change the value from '%' to
'all'. In your results page, you then need this:
if ($_GET['year'] == 'all') {
$sql = 'SELECT * FROM tablename';
}
else {
$sql = 'SELECT * FROM tablename
WHERE DATE_FORMAT(DT_DATESUB, '%Y') = '. $_GET['year'];
}
--
David Powers
Author, "Foundation PHP 5 for Flash" (friends of ED)
Co-author "PHP Web Development with DW MX 2004" (Apress)
[url]http://computerbookshelf.com[/url]
David Powers Guest



Reply With Quote

