I have two tables that I would like to work together (stories and events). Stories is a table that is used to produce articles on a website and events is a series of events put into a table. I would like to be able to add events to story based on the data in the story table.

Each story in stories has a unique Story_Code and also has fields like events1, events2, events3, events4 etc.

Each event in events has a unique Event_Code.

I would like to be able to have the user when posting a story in the stories table to be able to enter the Event_Code and that would pull in the data from the events table, but I am at a loss as to how to do it.

Currently, I can pull them based on the date as follows:

("SELECT * FROM events where Date = '2014-11-22' order by Icon ASC, Date DESC, Timestamp DESC")

What I want to do is change the where clause to fetch the event_codes specified by the user in the story table by story_code.

I think I need to define a variable for events1, events2 etc and then once it is defined, I can use that in my where clause.

Any help would be appreciated...

Recommended Answers

All 2 Replies

Member Avatar for diafol

I don't think you have the right structure. I would create a link table:

story (as you have it but without events1, events2... fields)
events (as you have it)
story_events (se_id, story_id, event_id)

Thanks Diafol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.