Hi, I have a mysql table containing news data and categories and i'm trying to slect all data within a certain category. I didn't think far enough ahead so i'm currently not using a normalised table at some point i may go back and re-write that portion to use a normalised table.
Here is my table structure
+---------+------------+------------+--------+----------+
| news_id | news_title | news | cat_id | date |
+---------+------------+------------+--------+----------+
| 1 | title1 | blahblah |1,2,4,6 |2009-11-24|
+---------+------------+------------+--------+----------+
| 2 | new title | text 123 | 2 |2009-01-24|
+---------+------------+------------+--------+----------+
| 3 | new title3 | text 3 | 2,19,6 |2009-02-24|
+---------+------------+------------+--------+----------+
Let's say I want to return all results for category 2 I am trying to use this statement.
$query= mysql_query("SELECT id FROM `news_data` WHERE FIND_IN_SET('" . str_replace(',',"',cat_id) OR FIND_IN_SET('",$cat_id)."',cat_id)") or die(mysql_error());
This returns the results for news id's 2 and 3 because they both start with "2". The first news id is not selected because "2" is the second value. I know it's something simple wrong with the mysql statement and I'm hoping someone will be able to help me out.
Thanks, Brooke