SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <?php foreach (get_images...

    Hi, when a user submits a post (forum post) with an image attached I have it so the image URL inserts in a db table. When I link to the file on the view_topic.php page, every post loads all the images that have been submitted rather than the one the is relevant to the post it was submitted with.

    Here is the line of code I am using to load the image for the correct place:

    Code:
    <?php foreach (get_images($file_name) as $image) { ?>
    					<tr>
    						<td valign="middle" align="center" height="140" width="120"><div id="galleryImage"><a href="/images/gallery/<?php echo $image['image_url']; ?>" target="_blank"><img src="/images/gallery/thumbnails/<?php echo $image['image_url']; ?>" border="0" alt="<?php echo $topic['subject']; ?>" title="<?php echo $topic['subject']; ?>" /></a></div></td>
    					</tr>
        				<?php } ?>
    I am not sure how to load it so the image just shows on the post it was submitted with. If anyone has any suggestion or tips that would be great.

    Thanks,

    Paul

  2. #2
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use previously saved image URL instead of this get_images function

  3. #3
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, would it be a case of doing something like this...

    Code:
    <?php foreach (image_url($file_name) as $image) { ?>
    Not 100& sure on the correct method to use the previously saved image URL as you mentioned.

  4. #4
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, it wouldn't
    there is no function called image_url and there is only one imaje url, so, you don't need any loop at all.
    image url being printed the same manner as text message does.

  5. #5
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, it all makes sense until the print bit - can you explain that a wee bit more, or know of any information pages on it that would be cool. Thanks

  6. #6
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still trying to suss this one - I am officially useless

  7. #7
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    I think what shrapnel N5 is saying is that if you have brought the image text field from the database it arrives in a text base format i.e the image database record for person 1 is /images/gallery/thumbnails/imagename.jpg . The image TEXT that is returned from the database is not an array so there is no need to use the foreach function. You just need to echo it out without the foreach bit.

    Maybe im getting the wrong end of the stick here but I think that is pretty much it.

    If im wrong, can you describe what data is in the cell you are bringing back from the database query.

    And BTW your not useless, we've all been there.

    Keith

  8. #8
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Keith, thanks for the reply.

    The image that is submitted to the DB table, is in a seperate table to the one of the post itself.

    The forum post, with subject, message and other fields are submitted to a forum_posts table, and the image that is submitted with the post goes to gallery_images table.

    In the gallery_images, when an image is submitted it simple submits the username, and random numbers - test-732647834.jpg

    Just need to pull the gallery_images image with the correct post.

    echo didn't work.

  9. #9
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right, I am trying to do it now so the 'image_url' cell is within the forum_post table, rather than the gallery_images.

    When I insert the image_url cell into the INSERT... info all I return from my post when all the fields are filled in is blank - I check the MySQL db table forum_posts and it says no data was submitted. As soon as I remove image_url from there, and post it works fine. It worked for gallery_images and not forum_posts which is strange. I have installed the cell for both tables exactly the same.

    Code:
    $db->query("INSERT INTO " . $config['db']['prefix'] . "forum_posts (topic_id, user_id, ad_type, pet_type, breed, gender, colours, dob, available, price, message, username, first_name, last_name, phone, email, image_url, date_created, is_first) VALUES ($topic_id, $user_data[user_id], '$ad_type', '$pet_type', '$breed', '$gender', '$colours', '$dob', '$available', '$price', '$message', '$username', '$first_name', '$last_name', '$phone', '$email', " . time() . ", 1)");
    		$post_id = $db->insert_id();


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •