jonybigude Posted June 7, 2014 Share Posted June 7, 2014 I built a CMS system using CKEditor and KCFinder that store information od a databse via textarea/php. So far so good! The issue comes to when I want to store and display images that link to themselves. The way I am storing images is exactly the same: There is a textarea where I insert an image via KCFinder/CKEditor. The image is uploaded to the server and the path stored at the database. Later I try to pick up that path from the database to display the image and because I want the image to link to itself, I try to use the same method to insert the url on the link. Problem? The link is missing and the images are not displaying. Can anyone point me the error and suggest any solution? I would be so thankful!CODE:try {$DBH = new PDO('mysql:host=localhost;dbname=yourdb;charset=utf8', 'user', 'password');$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);$STH = $DBH->prepare('SELECT * FROM php_maskiner ORDER BY timestamp DESC');$STH->execute();$STH->setFetchMode(PDO::FETCH_OBJ);while($row = $STH->fetch()) {$title = $row->title;$entry = $row->entry;$images = $row->images;$img_url = $row->images;$img_pack = '<div class="mask3 span3"><a rel="prettyPhoto" href="'.$img_url.'"><img src="'.$images.'"></a></div>';}$DBH = null;} catch (PDOException $e) {echo '<div class="alert alert-standard fade in"><a class="close" data-dismiss="alert" href="#">×</a><strong>Can\'t read the database!</strong></div><br />'.$e;}<?php echo '<article class="span12 post">'.$img_pack.'<div class="inside"><div class="span8 entry-content"><div class="span12"><h2>'.$title.'</h2><p>'.$entry.'</p></div></div></div></article>';?>Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted June 7, 2014 Share Posted June 7, 2014 You sure? The HTML you posted is correct. The problem may lie in the css for the mask3 and/or span3 classes. Try removing the class definitions for the div containing the link and image. Do you see the link/images now? Also the whole <article></article> HTML bloxk should be part of the while loop, otherwise only the last record returned by your query will be displayed. Your while loop should be constructed something like this while($row = $STH->fetch()) { // using HEREDOC syntax // see http://php.net/heredoc for details echo <<<HTML <article class="span12 post"> <div class="mask3 span3"> <a rel="prettyPhoto" href="{$row->images}"><img src="{$row->images}"></a> </div> <div class="inside"> <div class="span8 entry-content"> <div class="span12"> <h2>{$row->title}</h2> <p>{$row->entry}</p> </div> </div> </div> </article> HTML; // DO NOT CHANGE THE ABOVE LINE - see link above for why } Quote Link to comment Share on other sites More sharing options...
jonybigude Posted June 7, 2014 Author Share Posted June 7, 2014 (edited) Yes, I am sure (unfortunately)...Here is the outputed HTML:<a src="/nysida/admin/kcfinder/upload/images/332805_3333.jpg" "="" href="<img alt=" rel="prettyPhoto"> "> <img "="" src="<img alt="></img> "></a> Edited June 7, 2014 by jonybigude Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted June 7, 2014 Share Posted June 7, 2014 What? That HTML does not match what you posted in your OP. What is the output of var_dump($row->images); Quote Link to comment Share on other sites More sharing options...
jonybigude Posted June 7, 2014 Author Share Posted June 7, 2014 I am starting to wonder if this is a problem caused by CKEditor... This is the code that CKEditor inserts on the database:<img alt="" src="/nysida/admin/kcfinder/upload/images/1307594_10243178.jpg" /> Anyway, the answer to your question is: NULL Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.