PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
SELECT * FROM publications WHERE keyword1 LIKE '%$search_each%'OR keyword1 LIKE '%$search_each%'
So you're saying that it works if the operator immediately follows a closing quote? I didn't know that, but then of course I try very hard never to do that.
keyword1 LIKE '%$search_each%'OR keyword1 LIKE '%$search_each%'
maybe need keword2 or some other field as the 2nd field - the above statement is simply checking the same field twice identically, Soooooo if the item you KNOW is in the table but in a field other than keyword1, obviously it will return not found
keyword1 LIKE '%$search_each%'OR keyword1 LIKE '%$search_each%'
maybe need keword2 or some other field as the 2nd field - the above statement is simply checking the same field twice identically, Soooooo if the item you KNOW is in the table but in a field other than keyword1, obviously it will return not found
Thanks, but I have been searching the keywords in 'keyword1' field. I tried adding a different search criteria, but I still get no results...
<?PHP
/* USE YOUR DB CONNECTION HERE */
include('db.php');
/* REPLACE THIS VALUE WITH A KNOWN VALUE */
$search_term = "ea";
/* REPLACE TABLE NAME AND FIELD NAME WITH YOURS */
$query = "SELECT * FROM addresses WHERE lastname LIKE '%$search_term%'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
/* REPLACE FIELD NAMES WITH TWO OF YOURS */
echo $row['lastname'] . " - " . $row['firstname'] . "<br/>";
}
?>
keyword1 LIKE '%$search_each%'OR keyword1 LIKE '%$search_each%'
maybe need keword2 or some other field as the 2nd field - the above statement is simply checking the same field twice identically, Soooooo if the item you KNOW is in the table but in a field other than keyword1, obviously it will return not found
You're not blind, but I guess I am. That's funny that something that obvious wasn't spotted immediately.
But this does raise the issue that whenever you have to search more than one field for the same search term, your table schema is not normalized, so you're going to continually have problems, not only searching, but potentially with other issues. Relational databases work properly only when their schema is normalized.
was the db.php supposed to be replaced by something like 'config.php' with this type of info..?
if($indexCheck == "yes")
{
//datbase
$db_user = "xx";
$db_pass = "xx";
$db_host = 'localhost';
mysql_connect($db_host,$db_user,$db_pass);
@mysql_select_db('a2288820_data') or die( "Unable to select database");
litebearer wrote:Simple test. Copy this to a temp file named search_me.php. The make adjustments per the comments ONLY.
<?PHP
/* USE YOUR DB CONNECTION HERE */
include('db.php');
/* REPLACE THIS VALUE WITH A KNOWN VALUE */
$search_term = "ea";
/* REPLACE TABLE NAME AND FIELD NAME WITH YOURS */
$query = "SELECT * FROM addresses WHERE lastname LIKE '%$search_term%'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
/* REPLACE FIELD NAMES WITH TWO OF YOURS */
echo $row['lastname'] . " - " . $row['firstname'] . "<br/>";
}
?>
It is supposed to be a COMPLETELY separate file from your other scripts.
The only changes you need to make to it are those commented.
then point your browser to the file
Since only you will see the contents of the file - you can put the actual database connection code in the file rather than doing any include
Last edited by litebearer on Mon Feb 14, 2011 12:56 pm, edited 1 time in total.
<?PHP
/* USE YOUR DB CONNECTION HERE */
include('config.php');
/* REPLACE THIS VALUE WITH A KNOWN VALUE */
$search_term = "master thesis";
/* REPLACE TABLE NAME AND FIELD NAME WITH YOURS */
$query = "SELECT * FROM publications WHERE type LIKE '%$search_term%'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
/* REPLACE FIELD NAMES WITH TWO OF YOURS */
echo $row['author1'] . " - " . $row['author2'] . "<br/>";
}
?>
litebearer wrote:It is supposed to be a COMPLETELY separate file from your other scripts.
The only changes you need to make to it are those commented.
then point your browser to the file