0

I have a one to many relationship and the tables in my database are as follows:

+---------------+         +-------------+
|     Route     |         |   Street    |
+---------------+         +-------------+
|route_id       |         |st_id        |
|route_name     |         |street_name  |
|street_ids:    |         +-------------+
|(st_1, st_2,   |
|st_3, st_n)    |   
+---------------+

In my Route table I stored the Street's st_id as string is it was saved with the street_name being checked in a form.

I want to display all the Streets included in a Route. I used explode function in PHP to get the st_ids from Route table. How can get the street_names from the Street table using the array result of the previous explode function?

In case my practice of storing the list of ids as string in a table is bad, I'll be open for suggestions.

Thanks.

M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118
Allen
  • 51
  • 1
  • 9
  • I suggest you try following a tutorial first, e.g. https://www.tutorialrepublic.com/php-tutorial/php-mysql-introduction.php – Eriks Klotins Aug 19 '20 at 07:27
  • 2
    Your data structure appears to be denormalised. I suggest you study relational database design beforehand – ADyson Aug 19 '20 at 07:33
  • Thank you. I just realized that the relationship is actually not a one-to-many. Routes can have many streets and streets can be included in many routes thus making it a many-to-many relationship. Thank you for your suggestions. – Allen Aug 19 '20 at 08:47
  • Does this answer your question? [Is storing a delimited list in a database column really that bad?](https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad) – Dharman Aug 19 '20 at 09:18

0 Answers0