Jump to content

simple database search


networkthis

Recommended Posts

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.

Link to comment
Share on other sites

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???

Link to comment
Share on other sites

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???

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.