1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

PHP, MySql, html, and characters such as single quote

Discussion in 'Software Development' started by andynic, May 8, 2015.

Thread Status:
Not open for further replies.
  1. andynic

    andynic Thread Starter

    Joined:
    May 25, 2007
    Messages:
    386
    Why would the same SQL command fetching the same row from the database, treat characters such as single quotes differently in two different contexts?
    Context 1: one row for a particular primary key;
    Context 2: all rows.
    In terms of the results shown below, the focus is on the contents of a varchar column, t.korte_omschrijving, containing the phrase: In de bundel ‘In mijn verbeelding’ bieden tien dichters ....

    The PHP code:
    Code:
            $sqlCmd     = "select t.*,            
                                    case t.maand 
                                         when  null   then ''
                                         when  1      then 'jan' 
                                         when  2      then 'feb' 
                                         when  3      then 'maa' 
                                         when  4      then 'apr' 
                                         when  5      then 'mei' 
                                         when  6      then 'jun' 
                                         when  7      then 'jul' 
                                         when  8      then 'aug' 
                                         when  9      then 'sep' 
                                         when 10      then 'oct' 
                                         when 11      then 'nov' 
                                         when 12      then 'dec' 
                                    end                                          as maand,
                                  concat(t.jaar, 
                                         if (length(t.maand)=1, concat('0', t.maand), t.maand), 
                                         if (length(t.dag)=1, concat('0', t.dag), t.dag)) as pubDateYYYYMMDD,
                                  a.auteur                                       as auteur,
                                  a.over                                         as auteurBio,
                                  (select p.value 
                                   from  t_parameters p
                                   where p.name = 'EMAIL_REACTIES_BESTELLINGEN') as reactiesBestellingen
                           from   t_auteurs    a,       
                                  t_titels     t
                           $whereClause 
                           $orderByClause"; 
    
            $sqlCmdHndl = $dbObj->execSqlCmd($fctNm, $dbObj, $sqlCmd, $bindArr);
            $sqlCmdHndl->setFetchMode(PDO::FETCH_ASSOC);
    
            $i = 0; $d = array();
            while ( $row = $sqlCmdHndl->fetch() ) {
              $d[$i] = $row;
    if ( $d[$i]['id_tit'] == 45 ) { 
    echo "<br /><font style='color:red; font-weight:bold'>" . __FILE__ . "... fctNM = $fctNm ... frmFct = $frmFct ... " . "</font><br />\n";
    echo "872 sqlCmd = $sqlCmd<br /><br />";
    }
              $i++;
            }
    
    Using an echo command, shown below is the command for each of the two contexts. The only difference that I see is the "where" clause and "order by" clause.
    Context 1 echoed sqlCmd:
    select t.*,
    case t.maand when null then '' when 1 then 'jan' when 2 then 'feb' when 3 then 'maa' when 4 then 'apr' when 5 then 'mei' when 6 then 'jun' when 7 then 'jul' when 8 then 'aug' when 9 then 'sep' when 10 then 'oct' when 11 then 'nov' when 12 then 'dec' end as maand,
    concat(t.jaar, if (length(t.maand)=1, concat('0', t.maand), t.maand), if (length(t.dag)=1, concat('0', t.dag), t.dag)) as pubDateYYYYMMDD,
    a.auteur as auteur,
    a.over as auteurBio,
    (select p.value from t_parameters p where p.name = 'EMAIL_REACTIES_BESTELLINGEN') as reactiesBestellingen
    from t_auteurs a, t_titels t
    where a.id_aut = t.id_aut
    and t.id_tit = :id_tit

    Context 1 result: t.korte_omschrijving = In de bundel â&#8364;&#732;In mijn verbeeldingâ&#8364;&#8482; bieden tien dichters


    Context 2 echoed sqlCmd:
    select t.*,
    case t.maand when null then '' when 1 then 'jan' when 2 then 'feb' when 3 then 'maa' when 4 then 'apr' when 5 then 'mei' when 6 then 'jun' when 7 then 'jul' when 8 then 'aug' when 9 then 'sep' when 10 then 'oct' when 11 then 'nov' when 12 then 'dec' end as maand,
    concat(t.jaar, if (length(t.maand)=1, concat('0', t.maand), t.maand), if (length(t.dag)=1, concat('0', t.dag), t.dag)) as pubDateYYYYMMDD,
    a.auteur as auteur,
    a.over as auteurBio,
    (select p.value from t_parameters p where p.name = 'EMAIL_REACTIES_BESTELLINGEN') as reactiesBestellingen
    from t_auteurs a, t_titels t
    where a.id_aut = t.id_aut
    order by jaar desc, maand desc, dag desc

    Context 2 result: t.korte_omschrijving = In de bundel &#8216;In mijn verbeelding&#8217; bieden tien dichters

    Any ideas what might be causing this?

    Thanks for your help.
    Andynic
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - MySql html characters
  1. riiiiiya
    Replies:
    0
    Views:
    252
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1147934

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice