ohdang888 Posted March 30, 2008 Share Posted March 30, 2008 i think i need to use a Mysql OR statement..... But i don't know how (and google isn;t helping either) I am creating a search option within my site. It searches for many things, through tags, titles, etc. So i have been using different queries for different field.. This is what mine is right now. 1. query for tags Like search 2. query for title Like search etc. But that is creating many duplicates results... Any ideas? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/98652-mysql-or/ Share on other sites More sharing options...
unidox Posted March 30, 2008 Share Posted March 30, 2008 Code? Quote Link to comment https://forums.phpfreaks.com/topic/98652-mysql-or/#findComment-504869 Share on other sites More sharing options...
ohdang888 Posted March 30, 2008 Author Share Posted March 30, 2008 <?php echo '<table class="main_body"><tr><td width="150">'; // code For multiple tags $tags = explode(',', $search); //set within the varable names for($i=0; $i<count($tags); $i++){ $res[]=trim($tags[$i]); } foreach($res as $x){ mysql_select_db("games") or die(mysql_error()); $result = mysql_query("SELECT `title`,`type`,`game_picture_url` FROM `game` WHERE upper(tags) LIKE upper('%$x%') ")or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ echo '<center><table width ="150px"><tr><td>'; echo '<a href="game.php?title='; echo $row['title'].'">'; echo '<IMG SRC="gamepic/'; echo $row['game_picture_url']; echo '"'.' WIDTH="90"'.' HEIGHT="90"></a></td>'; echo '<td class="search_game_info"><a href ="game.php?title=';//start of link code echo $row['title']; echo '">'; echo $row['title']; echo '</a></br>';// end of link code echo '('; echo $row['type']; echo ')</td></tr></table>'; echo '</td></tr><tr><td>'; } } $result = mysql_query("SELECT * FROM `game` WHERE upper(title) LIKE upper('%$search%') ")or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ echo '<center><table width ="150px"><tr><td>'; echo '<a href="game.php?title='; echo $row['title'].'">'; echo '<IMG SRC="gamepic/'; echo $row['game_picture_url']; echo '"'.' WIDTH="90"'.' HEIGHT="90"></a></td>'; echo '<td class="search_game_info"><a href ="game.php?title=';//start of link code echo $row['title']; echo '">'; echo $row['title']; echo '</a></br>';// end of link code echo '('; echo $row['type']; echo ')</td></tr></table>'; echo '</td></tr><tr><td>'; } echo '</td></tr></table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/98652-mysql-or/#findComment-504872 Share on other sites More sharing options...
maxudaskin Posted March 30, 2008 Share Posted March 30, 2008 Are you asking how to do it? There are two ways that I know: <?php /* Way One */ mysql_query("SELECT * FROM table WHERE this = 'this' OR that = 'that'"); /* Way Two */ mysql_query("SELECT * FROM table WHERE this = 'this' || that = 'that'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/98652-mysql-or/#findComment-504884 Share on other sites More sharing options...
sasa Posted March 30, 2008 Share Posted March 30, 2008 try foreach($res as $x) $w[] = " upper(tags) LIKE upper('%$x%') "; $w = implode('OR', $w); mysql_select_db("games") or die(mysql_error()); $result = mysql_query("SELECT `title`,`type`,`game_picture_url` FROM `game` WHERE $w")or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ echo '<center><table width ="150px"><tr><td>'; echo '<a href="game.php?title='; echo $row['title'].'">'; echo '<IMG SRC="gamepic/'; echo $row['game_picture_url']; echo '"'.' WIDTH="90"'.' HEIGHT="90"></a></td>'; echo '<td class="search_game_info"><a href ="game.php?title=';//start of link code echo $row['title']; echo '">'; echo $row['title']; echo '</a></br>';// end of link code echo '('; echo $row['type']; echo ')</td></tr></table>'; echo '</td></tr><tr><td>'; } Quote Link to comment https://forums.phpfreaks.com/topic/98652-mysql-or/#findComment-504905 Share on other sites More sharing options...
ohdang888 Posted March 30, 2008 Author Share Posted March 30, 2008 that solved it. Thanks sasa! Quote Link to comment https://forums.phpfreaks.com/topic/98652-mysql-or/#findComment-504918 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.