Wilcard character problem in PHP/MySQL

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default Re: Wilcard character problem in PHP/MySQL

    goldstein wrote:
    > 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?
    It's got nothing to do with DATE_FORMAT; it's your use of a wildcard
    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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139