04-30-2019, 03:45 PM
(04-30-2019, 09:06 AM)astropos Wrote: I'm doing something similar right now. Hope I've read and understood your question properly
I have the main table 'items' where I create one record for each post. My input form is rather like yours in that users can enter text or upload an image, or both.
Before you store the item in the db, you can determine which of the input fields have been filled (is it text or image or both) and then assign an 'item_type' code before INSERTing. This way you have only one row per 'item'. Then when you come to read the table for display, you can use program logic (switch, or multiple if's) to decide what to do based on the 'item_code' rather than multiple queries. Subesquent comments and comment replies would go in another two seperate tables.
proto:
receive $_POST
use some logic to determine what it is
[eg] if text field is not empty the item code is 't'
[eg] if image field is not empty the item code is 'i'
else item code is 'z'
INSERT INTO items (textfield,imagefield,code)
---
SELECT * FROM items [WHERE] ORDER BY date DESC
if(item_code = 't') echo '<p>xyz</p>'
if(item_code = 'i') echo '<img src=xyz />'
if(item_code = 'z') echo '<p>xyx</p><img src=xyz />'
else echo 'this record is malformed'
The above is just a rough example and not definitive(!) Does it make any sense?
https://cw3.cloudwidgets.co.uk/ (src avail if you'd like)
Very cool! Looks pretty slick!
I've got a working example of my "wall" at https://witches.community/users/wall.php but the code is terrible lol (but it works!)