blueman378 Posted December 6, 2007 Share Posted December 6, 2007 hi there, i have a table called games. it has things like the file link, the name ect, it also has a column called keywords, i was wondering is it possible to count each word in that column as a seperate result, eg with mysql if you search keywords and your word is mouse, it searches all the games and if the word mouse is in the keyword column for that game then that result is shown, cheers matt Quote Link to comment https://forums.phpfreaks.com/topic/80399-solved-mysql-multiple-results-in-one-column/ Share on other sites More sharing options...
BenInBlack Posted December 6, 2007 Share Posted December 6, 2007 select * from games where keywords like '%mouse%' Quote Link to comment https://forums.phpfreaks.com/topic/80399-solved-mysql-multiple-results-in-one-column/#findComment-407654 Share on other sites More sharing options...
blueman378 Posted December 6, 2007 Author Share Posted December 6, 2007 hi there, i tried using this <?php include("include/session.php"); $key = $_POST['key']; global $database; $q = "SELECT * FROM " . Games . " WHERE keyword LIKE '$key' ORDER BY `gName` ASC "; $result = $database->query($q) or die("Error: " . mysql_error()); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if( $num_rows == 0 ){ return 'Game Not Found!'; } while( $row = mysql_fetch_assoc($result) ) { echo $row[gName]; } ?> but i just get a blank page no errors or anything, and when i change the keyword to one that does not exist i get nothing the url is localhost.php?key=Space when i use <?php include("include/session.php"); echo "<pre>"; print_r($_GET); die("</pre>"); $key = $_POST['key']; global $database; $q = "SELECT * FROM " . Games . " WHERE keyword LIKE '$key' ORDER BY `gName` ASC "; $result = $database->query($q) or die("Error: " . mysql_error()); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if( $num_rows == 0 ){ return 'Game Not Found!'; } while( $row = mysql_fetch_assoc($result) ) { echo $row[gName]; } ?> i get Array ( [key] => Space ) when i use: <?php include("include/session.php"); $key = $_POST['key']; global $database; $q = "SELECT * FROM " . Games . " WHERE keyword LIKE '$key' ORDER BY `gName` ASC "; $result = $database->query($q) or die("Error: " . mysql_error()); /* Error occurred, return given name by default */ die("SQL:<br>$q"); $num_rows = mysql_numrows($result); if( $num_rows == 0 ){ return 'Game Not Found!'; } while( $row = mysql_fetch_assoc($result) ) { echo $row[gName]; } ?> i get SQL: SELECT * FROM Games WHERE keyword LIKE '' ORDER BY `gName` ASC Quote Link to comment https://forums.phpfreaks.com/topic/80399-solved-mysql-multiple-results-in-one-column/#findComment-407662 Share on other sites More sharing options...
~n[EO]n~ Posted December 6, 2007 Share Posted December 6, 2007 Change $_POST['key'] to $_GET['key'] and check Quote Link to comment https://forums.phpfreaks.com/topic/80399-solved-mysql-multiple-results-in-one-column/#findComment-407679 Share on other sites More sharing options...
blueman378 Posted December 6, 2007 Author Share Posted December 6, 2007 mwahahha that worked perfectly thanks Quote Link to comment https://forums.phpfreaks.com/topic/80399-solved-mysql-multiple-results-in-one-column/#findComment-407691 Share on other sites More sharing options...
BenInBlack Posted December 6, 2007 Share Posted December 6, 2007 i guess MySql is forgiving and assumes the "%", In my years of sql keywords like '%mouse%' = contains keywords like 'mouse% = begins with keywords like '%mouse' = ends with to me it is safer to use the % (which is actually a wildcard for Many chars) Quote Link to comment https://forums.phpfreaks.com/topic/80399-solved-mysql-multiple-results-in-one-column/#findComment-407718 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.