Reputation: 27
I am trying to make a system that manages a lot of articles and some articles are needed in more than one article series.
I am wondering how I can give one row in Mysql several unique ID´s and extracting them from the database with PHP.
It only reads the first ID and not the next. I have tried seperating them with a comma, but if I write 10, 122. Only 10 will be read as an ID and 122 will be ignored.
I am not very skilled with programming, but I am doing my best to learn it, Hope you can help me! :-)
The code I use to sort the articles in the system.
$id=$_REQUEST['id'];
$ro=mysql_query("SELECT * FROM blog_articles
WHERE fk_semikatagori_id=".$id."
ORDER BY ABS(sortering) ASC") or die(mysql_error());
Upvotes: 1
Views: 119
Reputation: 780724
If you can't fix the table design, use FIND_IN_SET
:
$ro=mysql_query("SELECT * FROM blog_articles
WHERE FIND_IN_SET($id, fk_semikatagori_id)
ORDER BY ABS(sortering) ASC") or die(mysql_error());
Upvotes: 1
Reputation: 899
Each article is unique, right? Keep it having a unique ID. What you should do is create an additional table, like @user574632 has suggested, where you don't have any unique fields but this will allow you to create your "categories" (or "series") and add each unique article to that table. You then search THAT table to obtain all the IDs of articles that are supposed to be in a series.
E.g.
Articles
========
ID | Title | Body
1 | My Article | This is my article
2 | StackExchange | My article on Stack Exchange...
Categories
========
SeriesID | ArticleID
1 | 1
1 | 2
2 | 1
You then query the categories table to obtain all the article IDs you require for your series...
Upvotes: 2