Forum Moderators: coopster

Message Too Old, No Replies

relating articles by checking checkboxes

         

mattennant

9:48 am on Sep 1, 2008 (gmt 0)

10+ Year Member



Hi There

i'll be honest here, i posted this a while back on another forum and i realise what i am trying to do will have normalisation issues, but i was curious if there is a quick n dirty solution i could implement, while i get my head round updating ,inserting multiple checkboxes into various tables the right way.

the idea is that everytime say for example a news item is added in the cms, the admin will check 'check boxes' of the categories that story falls into

[] backpain
[] fitness training
[] alternative therapy etc etc

at the moment i am storing the array as a comma seperated array in a column called keywords (bad i know)

so far all well and good i retrieve the data as follows


do {
$nkw = explode(',',$row_news['keywords']);
if (($row_news['article_id']) ==(in_array($row_article['keywords'], $nkw))){
echo '<li><a href="mat_news.php?article_id=' . $row_news['article_id'] . '" target="_self" title="'.$row_news['headline'] .'">' . $row_news['headline'] . '</a></li>';
}
} while ($row_news = mysql_fetch_assoc($news2));

this works fine if there is an exact match from the checked checkboxes, ie both articles have just backpain checked

but i want to relate the articles even if there is just a single match from one of the checkboxes,

ie article one has back pain and fitness training checked
article 2 has just backpain checked

any help much appreciated

mat

IndiaMaster

11:18 am on Sep 1, 2008 (gmt 0)

10+ Year Member



I think you can use a query like :
$sql="select * from table_name where keywords like '%backpain%'"

mattennant

2:11 pm on Sep 1, 2008 (gmt 0)

10+ Year Member



no Luck with that am afraid , am thinking i need to explode the array into their own variables and run the through them one at a time, ie if backpain is 1 and fitness training is three, they appear in a cell like this 1,3,

the explode makes the array into 13 rather than 1 and 3, could this make sense i wonder?