4 Replies - 388 Views - Last Post: 10 May 2015 - 12:14 AM Rate Topic: -----

#1 Pest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-June 13

Making a dynamic post from sql DB to Interface

Posted 09 May 2015 - 09:43 AM

Hi guys,

To the best of my knowledge, I haven't come across this topic on this site, or anywhere else for that matter. If what I am about to ask has previously been posted then I do apologize and ask that you point me in the right direction.

I am in the midst of creating a website that requires information to be sourced from a database and when received, creates a post to the webpage that looks good rather than just formatted text or in a table. I'm thinking more along the lines of how facebook does this, where you create a status and it creates a "box" containing the post.

I know how to do the database queries etc, i just dont know how to make the new post, putting the content where it needs to go. Thinking how i would do it in other programming languages I'd ideally create a class/structure that would contain all the variables and create a new instance of it when needed. I just however haven't found a good tutorial for this in PHP hence my post.

Here is a picture of the idea I'm playing with where there are separate database records displayed like "posts" containing photos, titles, and contents.

Posted Image

Any help in this will be so greatly appreciated. I am a little new to PHP so if you know of any sample code/tutorials that I can reference to do this that will be even better.
Thank you all in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Making a dynamic post from sql DB to Interface

#2 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6541
  • View blog
  • Posts: 26,480
  • Joined: 12-December 12

Re: Making a dynamic post from sql DB to Interface

Posted 09 May 2015 - 03:39 PM

You would use PHP to construct the HTML of the boxes. The box itself could be a div, although I would probably stick with a table with a single column. You insert other elements into the box: divs, paragraphs, spans, whatever is appropriate. You can give each element a class-name and create a CSS stylesheet to style them.

You might not find a specific tutorial for something like this, because it is just basic HTML and CSS.

This post has been edited by andrewsw: 09 May 2015 - 03:42 PM

Was This Post Helpful? 0
  • +
  • -

#3 Pest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-June 13

Re: Making a dynamic post from sql DB to Interface

Posted 09 May 2015 - 11:50 PM

Thank you for the reply. It really helps for the way forward and i have an idea where to search for the last bit of logic thats a little cloudy which is to read each field into a specific named class element. The basics styling to do with HTML and CSS is sound with me, whats hindering my progress is linking the PHP read in into the div/table containing the elements and making a new complete structure on the fly as the records in the database change. Im thinking in logical order of execution.
  • connect to DB (i know how)
  • have loop reading select query's return into an array (i know how)
  • create a new "box" for each element in the array (this is where im getting lost)
  • take each element in the array's index and fill individual elements of the box (para's, H tags, Spans etc) - also a little cloudy on how to implement this
  • apply styling to each box (i know how to do this)


do you or anyone else reading this have an idea where i can find a tutorial or sample on how this is done? Alternatively, what would you or anyone suggest to accomplish my end goal? Is there an easier way to make a dynamic and styled feed of records from a database? I really am open to suggestions and am willing to change up logic if it works out easier.

But thanks again for the help, i really do appreciate it.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6541
  • View blog
  • Posts: 26,480
  • Joined: 12-December 12

Re: Making a dynamic post from sql DB to Interface

Posted 10 May 2015 - 12:01 AM

It is no different to filling in values into table cells, for which there are very many tutorials; practically every substantial PHP tutorial includes examples of displaying data retrieved from a database. For example,
echo "<span>{$row[field_name]}</span>";

or
echo "<p class='some_class'>{$row[field_name]}</p>";

This post has been edited by andrewsw: 10 May 2015 - 12:02 AM

Was This Post Helpful? 0
  • +
  • -

#5 Pest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-June 13

Re: Making a dynamic post from sql DB to Interface

Posted 10 May 2015 - 12:14 AM

View Postandrewsw, on 10 May 2015 - 12:01 AM, said:

It is no different to filling in values into table cells, for which there are very many tutorials; practically every substantial PHP tutorial includes examples of displaying data retrieved from a database. For example,
echo "<span>{$row[field_name]}</span>";

or
echo "<p class='some_class'>{$row[field_name]}</p>";


wow this really helps me, thank you so much for this hey. I think i have all i need to get where i need to. I appreciate all the help, thank you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1