Jump to content

Cant show and link to images


jonybigude

Recommended Posts

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!

 

Link to comment
Share on other sites

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
}
Link to comment
Share on other sites

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 by jonybigude
Link to comment
Share on other sites

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 :-\

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.