S
S
Sergey Maley2015-04-19 14:15:15
PHP
Sergey Maley, 2015-04-19 14:15:15

How to make posts just with text and text + photo?

It is necessary that the posts on the site work, for example, on Twitter or Vkontakte.
That is, if I want to publish just text, then just text will be published, well, there are no problems with this, the problem is how to make such a post, for example, text + photo.
I think what needs to be done in the table with posts is two more fields hasImg and imgName. And after already when deriving from the database, check with if'om if hasImg = 1 then display the picture for display. So? or what do you recommend?
Here is an example of posting a photo and text from twitter...
d084789e8b0149789a4a2383b2a4525c.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Talalaev, 2015-04-19
@spesher

If you do it in a simple and good way:
1. Post table entry:

id
title
text
...

2. Table entry imgs:
id
img
post_id
...
. It’s good to link these fields in the database (depending on the engine)
In the model, you describe that the post has pictures, and in the template, pictures are simply displayed if there is at least one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question