networkthis Posted October 11, 2008 Share Posted October 11, 2008 Is it very difficult to search for a specific term in a database table then output only what matches the content? Lets say I have a description and want only the descriptions that have the word linguist in the descritption to popup up on the page how would I go about that...any ideas... I already have the db all done as well as the script to connect to the database and display all relevant information on my pages. I would like to have just the pages matching specific keywords to popup. I have an rss feed now that will display the last 25 things posted but would like to generat more specific rss feeds by having only the ones I have searching the db with specific keywords to popup. All info is greatly appreciated. Thank you. Quote Link to comment Share on other sites More sharing options...
AV1611 Posted October 11, 2008 Share Posted October 11, 2008 select * from table where field like '%linguist%' rss feel and searching are not the same thing in all cases. Do you want to filter the rss feed, or do you want to modify the rss feed? That makes a BIG difference... Quote Link to comment Share on other sites More sharing options...
networkthis Posted October 12, 2008 Author Share Posted October 12, 2008 OK this is what I have for a basic output of the info for an example. This works and displays all my info from the mysql tables without a search. <?php $username = "username"; $password = "password"; $hostname = "my local host"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; //select a database to work with $selected = mysql_select_db("mydb",$dbhandle) or die("Could not select mydb"); $query = "SELECT id, job_title, short_description FROM `jb_jobs` WHERE status = \"active\" ORDER BY time DESC LIMIT 100"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "ID :{$row['id']} <br>" . "Title : {$row['job_title']} <br>" . "Description : {$row['short_description']} <br><br>"; } //close the connection mysql_close($dbhandle); ?> This is what I have tried with many variations implementing the LIKE '%linguist%' into the query SELECT statement, but I cannot seem to get it to work. I know this has to be easier then this!! I am losing my mind any info would be greatly appreciated. Thank you!!! <?php $username = "username"; $password = "password"; $hostname = "my local host"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; //select a database to work with $selected = mysql_select_db("mydb",$dbhandle) or die("Could not select mydb"); $query = "SELECT id, job_title, short_description LIKE '%linguist%' FROM `jb_jobs` WHERE status = \"active\" ORDER BY time DESC LIMIT 100"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "ID :{$row['id']} <br>" . "Title : {$row['job_title']} <br>" . "Description : {$row['short_description']} <br><br>"; } //close the connection mysql_close($dbhandle); ?> I guess my question now would be where the heck does the LIKE '%%' part go at in a mysql search and is it possible to make it work the way I have it now??? Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 12, 2008 Share Posted October 12, 2008 LIKE belongs in the WHERE component http://www.tizag.com/mysqlTutorial/mysqlwhere.php Quote Link to comment Share on other sites More sharing options...
networkthis Posted October 12, 2008 Author Share Posted October 12, 2008 Thank you so very much for that example, it worked to perfection. Explained exactly what I wanted. I ended up simply changing the query statement to this.... <?php $query = ("SELECT * FROM jb_jobs WHERE short_description LIKE '%linguist%'"); Quote Link to comment Share on other sites More sharing options...
networkthis Posted October 12, 2008 Author Share Posted October 12, 2008 See what happens when you accidentaly hit enter before you are finished with the post!!! Anyways one final question. With the * in the statement is that simply just allowing the loading of all the columns in the database??? Instead of typing each one out individually??? Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 12, 2008 Share Posted October 12, 2008 Anyways one final question. With the * in the statement is that simply just allowing the loading of all the columns in the database??? Instead of typing each one out individually??? Correct. Quote Link to comment 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.