Path: csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.php Subject: Re: rawurlencode problem Date: Tue, 20 Oct 2015 00:00:16 +0200 Organization: PointedEars Software (PES) Lines: 143 Message-ID: <6395335.3oAvEOITrP@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1445292045 17759 eJwFwQERACAIA8BKAxmccRRZ/wj+c6VlVyQzKKq3wavJ5iAPzE11cXeNK9QOF/jm6cSaWh8TLREe (19 Oct 2015 22:00:45 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 19 Oct 2015 22:00:45 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYEBwCAIA7CXVqB1noMI/59gQhdUK0QFhyO3no7jclqYSmja9M5GY35zFhiZ2HstInXrMk13zlc5D0XBFbo= Cancel-Lock: sha1:tZqtHcY3xiVY4aj6VMqe9p3/VKs= X-NNTP-Posting-Host: eJwFwYEBwDAEBMCVqPxjHCT2H6F3MCrHD8GDxbq+cIlVaVQrH2fzdEoEXODWUhfJDzs2t34OSRDY Xref: csiph.com comp.lang.php:15706 Derek Turner wrote: > I'm using this: > > echo "
    "; > while ($row = $result->fetch_assoc()): > echo "
  1. ['name'])."\">" . $row['name'] . "
  2. \n\n"; > endwhile; > echo "
"; > > to provide links for screen-readers to various points in my page Please don’t. This is _not_ how one properly uses PHP in the 21st century. Instead, in your controller code, use the equivalent of $data = $result->fetch_all(MYSQLI_ASSOC); and in your view template (which you include() or require() through your controller code), the equivalent of
thereby cleanly *separating business logic from presentation*. Usually you want to define template variables instead of using $data. A template engine can be useful there, but is not required if your controller sets view "variables" instead; e.g. $data = $result->fetch_all(MYSQLI_ASSOC); $this->view->setVar('rows', $data); and then
    rows as $row): ?>
Also consider mysqli_result::fetch_object() which can convert records into model objects directly. You can store sets of model objects in a template variable, and then access object properties instead of array keys which has several benefits thanks to the possibility of implicit setters and getters: /* * There is no other way but a loop with mysqli; * PDO_Mysql has * * $links = $pdoStatement->fetchAll(PDO::FETCH_CLASS, 'Turner\\Link', * $mapping); * * instead. */ while (($obj = $result->fetch_object('Turner\\Link', $mapping))) { $links[] = $obj; }; $this->view->setVar('links', $links) and then
    links as $link): ?>
  1. name) ?>
Use instead of if you use PHP 5.4+: The “li” elements probably do not need a CSS class each; you can write stylesheets using the selector context .reader li to format them or their descendant elements instead. > $row['name'] may and does contain white spaces in many records. Given that users would want to use those references, it is prudent to replace consecutive white space in fragment identifiers with a different character that is easy for them to read and type, e.g. “-”. You can find this all over the Web. > The code works fine without the rawurlencode but fails validation Presumably with the W3C Markup Validator. > similarly this code lower down: > > while ($row = $result->fetch_assoc()): > echo "

" . $row > ['name'] . "

"; > etc. Same problem as above. Who is going to maintain this character mess? > works without the rawurlencode but fails validation as 'id' must not > contain white space. IDs are _not_ URLs. Use htmlspecialchars() there instead. > SO the link href and the id are identical apart from the leading # No, one is a *URI-reference*, the other is an *ID*. > PROBLEM: this passes validation but DOES NOT WORK. Of course it does not. > What am I missing???? The HTML(5) Specification, a decent tutorial on modern design patterns like MVC, and a keyboard with working Shift and Question Mark keys. IOW: -- PointedEars Zend Certified PHP Engineer Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.