php - How To Separate Mysqli Query result After Coma -
i bit confused @ 1 situation. have table called slam-book
in have column named favorite games. user enters data like
"cricket, foot ball, hockey, basket ball"
now want separate result , want give link like,
<a href="/game.php=cricket">cricket</a>, <a href="/game.php=foot-ball">foot ball</a>, <a href="/game.php=hockey">hockey</a>, <a href="/game.php=basket-ball">basket ball</a>
so, can list users specific interest, please me such result. want code can give me results #2 code.
it's hard 'guess' structure mysql database in order i'll try anyways.
if understood correctly example of column in database: cricket, foot ball, hockey, basket ball
if so, query below:
select favorite_games slam-book user_id=id
then iterate result set doing like:
foreach ($row = $result->fetch_assoc()) { // list of games $games = explode(',', $row['favorite_games']); // pretty print each game foreach ($games $game) { // replace space dash $clean_game = str_replace(' ', '-', trim($game)); echo "<a href="/game.php=$clean_game">ucwords($game)</a> } }
Comments
Post a Comment