1

i'm a newbie in php and Mysql. I've got a table called 'cat_filter' done like this

cat_filter_id   cat_filter_value    cat_filter_name               categories_id

5   Colore Metallo      Bianco                              13
2   Tipologia Schienale Rete                                11
3   Finiture            Cromata                             11
4   Tipologia Poltrona  Direzionale;Operativa;Visitatori    11

I've done this code :

$connessione=mysql_connect($db_host,$db_user,$db_password);
mysql_select_db($db_database,$connessione);     
$data = mysql_query("SELECT * FROM cat_filter WHERE categories_id=$current_category_id") or die(mysql_error());  echo '<p>';
while($info = mysql_fetch_array( $data )) 
{ 
echo ''.$info['cat_filter_value'] . ': <a href="index.php?main_page=advanced_search_result&keyword='.$info['cat_filter_name'] . '&search_in_description=1&categories_id='.$current_category_id . '">'.$info['cat_filter_name'] . '</a> ~ ';
}
echo '</p>';
mysql_close();

The works quite well, but i'd like taht if a field has more value separeted by this ';' the output will be separated for each (sorry for my english) .. is it clear ? Thanx in advance ! best regards. Francesco

0

1 Answer 1

1

Change the echo '' . $info['cat_filter_value'] line to perform a loop:

foreach (explode(';', $info['cat_filter_value']) as $value) {
    echo $value . ": ...";
}
Sign up to request clarification or add additional context in comments.

1 Comment

I've added your code ... last question. Is it possibile to print only once cat filter value ? Exemple : i've cat_filter_value 'Value1' cat_filter_name 'Name1;Name2;Name3' I'd like to print : Value1 : <a link with Name1>Name1</a> - <a link with Name2>Name2</a> - <a link with Name3>Name3</a> In this moment i have: Value1 : <a link with Name1>Name1</a> - Value1 : <a link with Name2>Name2</a> - Value1 : <a link with Name3>Name3</a> I hope ive been clear. Thanx in advance again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.