I'd like to change <?=$beard['comments']?>to <?=$comments?> to I can run the lower case, something like this: $comments = $row["comments"]; $comments = mb_convert_case($comments, MB_CASE_LOWER, "UTF-8"); Code (markup): But it doesn't work. If I ran strtolower on the $query, doesn't work either <? $number_of_items = 6; $query = "SELECT * FROM abc WHERE hidden = 0 ORDER BY date_submitted DESC LIMIT 0, $number_of_items"; $result = doQuery($query); while ($beard = mysql_fetch_assoc($result)) { ?> <a href="beard-<?=$beard['drawingID']?>-<?=$beard['comments']?>"><img src="/thumbnails/<?=$beard['drawingID']?>.png" class="thumbnail" alt="<?=$beard['comments']?> Drawing" border="0" style=""></a> <? } ?> Code (markup): Any thoughts? thanks
Well, first I'd stop using so many opening and closings of PHP, particularly the poorly supported and rarely enabled shorttag <? Then I'd stop using mysql_ functions like it's 2004 THEN I'd stop plugging string values into queries, making extra strings for nothing, etc, etc... guessing wildly: <?php $number_of_items = 6; // assumes $db is a connected PDO object /* turn off emulated prepares since that screws up LIMIT and native driver is more efficient */ $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $statement = $db->select(' SELECT * FROM abc WHERE hidden = 0 ORDER BY date_submitted DESC LIMIT 0, :numItems '); $statement->execute([':numItems' => 6]); while ($beard = $statement->fetch(PDO::FETCH_ASSOC)) { echo ' <a href="beard-', $beard['drawingID'], '-', mb_convert_case( $beard['comments'], MB_CASE_LOWER, 'UTF-8' ), '"> <img src="/thumbnails/', $beard['drawingID'], '.png" alt="', $beard['comments'], ' Drawing" class="thumbnail" /> </a>'; } ?> Code (markup): Though if I was going to use them for a href, I'd be doing MB_CASE_TITLE and then stripping out whitespace with a regex -- poof, InstantCamelCase... just in case your 'comments' has spaces in it. Likewise I'd probably URLEncode it as well.
Thanks and Wow I haven't even heard of most of these terms and pulls up this error: Call to a member function setAttribute() on a non-object
For that to function $db must be a connected PDO object (hence the comment) -- replacing the mysql_ functions you are currently trying to use. If you haven't declared a $db = new PDO( 'mysdl:hostname=localhost;dbname=database', 'username', 'password' ); Code (markup): Instead of the mysql_connect you are likely currently using (and should have stopped using eight years ago) then the above code won't work. Hence the "stop using mysql_ functions like it's still 2004" part... and hence the giant red warning boxes in the manual that have been there for over two years no warning you of the same! Which is why I look out upon the web with digust to the point of nausea at the number of poorly written buggy insecure tutorials still telling people to use mysql_ functions.
Try having MySQL do that for you: $query = "SELECT drawingID, LOWER(comments) as comments FROM abc WHERE hidden = 0 ORDER BY date_submitted DESC LIMIT 0, $number_of_items"; Code (markup): See if that makes a difference. Another option like @deathshadow mentioned switch to using PDO if that is an easy task to do. Also what type of field is comments?
LOWER is nice when it works, but I've found it to be unreliable unless you are 100% sure of your TABLE's encoding. It screws up too much when the stored data doesn't match the table encoding -- something most people never change from the default.