Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6221625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:10:03+00:00 2026-05-24T08:10:03+00:00

In an effort to learn more about php and mysql, I have been working

  • 0

In an effort to learn more about php and mysql, I have been working through a number of different tutorials and posts on building a simple blog site. I have a database that holds the necessary, usual suspects (ID, title, author, date, and post). In my php, I query the db, load all the suspects into the van and then echo each one when and where I need them – works brilliantly.

Now I want to go further. I would like to have the ability to add some images to the blog posts which, right now, are simply typed into the text table of the db. How do I go about building something like that? I have been looking everywhere for some kind of hint – basically Googling every combo of “MySQL PHP Blog insert images into post”, I can think of. There are lots of different software options, but I want to understand how to build it from scratch – No WordPress, Blogger, etc.

I am not trying to allow users to upload images. I just want to include images in the actual post, so that when I query the db to load the various php divs (title, author, date, and post) the post will include any pictures that I want displayed. [i.e. “Here is some sample text that I have been working with and a picture” (picture) “as you can see, the picture above is an example that I have placed in the actual blog post”.

How do I get the mysql query to load the post and add the pictures in the appropriate place? This is not about uploading the images to the server or the database. This is simply about reading the post’s text and including the images for that post in the appropriate spots. I do not want users to be able to upload anything at all, I just want the php page to output the title, the author, the date, and the post (complete with pictures).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:10:04+00:00Added an answer on May 24, 2026 at 8:10 am

    A few things to consider:

    • Do you want users to upload images through a form on the site, or are you going to be the only user, and uploading via FTP?
    • Are users going to type html into the text editor where they want the picture to show up, or are you going to parse out some kind of simple markup language (such as [img=”path/to/image.jpg”] )
    • Is the database actually necessary for what you are trying to accomplish?

    If your goal is to learn more about PHP, MySQL, and working with images, perhaps something like an image gallery with support for multiple albums may be a more straightforward way to learn what you want to learn. An example of what I am talking about can be found here (Disclosure: this links to the website I am building for my Wife’s photography business, but is relevant).

    Hope this helps!

    ::EDIT::
    Based upon the update to your question and the comment to my answer, there are two possible solutions I will recommend to you:

    The Easy Solution:
    Write some HTML in your post referencing the photo based upon where you uploaded it. tags are easy, and even Blogs such as wordpress will allow you to do this (so it’s not a cop-out) 🙂

    The Educational Solution:
    In each post, allow for some type of markup indicating where the image needs to be (such as [img]1[/img]… some content …[img]2[/img]… some more content ), and in your database link each photo ID to each post ID, along with the position you would like the photo to fill in the post. For clarity, that might be:

    Table photo_in_post:
    ----------------------------------
    |img_id  | post_id | img_position|
    |--------|---------|-------------|
    | 17     |  4      |  1          |
    |--------|---------|-------------|
    | 3      |  4      |  2          |
    |--------|---------|-------------|
    | 4      |  2      |  1          |
    |--------|---------|-------------|
    

    After grabbing the text of the post, perhaps you could run a query such as:

    select * from photo_in_post join img on img.id = photo_in_post.img_id where photo_in_post.post_id = 4 order by photo_in_post.img_position;
    

    and then loop through your post replacing each occurrence of [img]NUMBER[/img] with an image tag generated based upon the Database result corresponding with the img_position inside the tag. Alternately, you could even loop through the database results and do something along the lines of:

    str_replace("[img]".$row['img_position']."[/img]", "Generated image tag", $postContents);
    

    That would probably be enough to get you started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.