The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To: SELECT 1 or 2 rows depending on a DISTINCT single row
#6
(04-30-2019, 09:06 AM)astropos Wrote: I'm doing something similar right now. Hope I've read and understood your question properly Smile

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!)
  Reply


Messages In This Thread
RE: How To: SELECT 1 or 2 rows depending on a DISTINCT single row - by Malatesa - 04-30-2019, 03:45 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)