View Single Post
  #1 (permalink)  
Old 06-21-04, 04:33 PM
dawggy505 dawggy505 is offline
Newbie Coder
 
Join Date: May 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
mysql/php search script

alright, i made this php script to search through a mysql database. it is very small and the script is very easy but i am having a few problems.

i want the user to type in the value of the search (duh) and have the script find it.

the html on the first page it this:

<html>
<head><title> Search | langauges </title>
</head>
<body>
<h2> Search for a shop</h2>
<br>
<form action="resultsbyname.php" method="post">
Pleae enter the name, or part of the name of the language you are looking for:<br>
<input name="name" type="text">
<br>
<input type="submit" value="Search">
</form>

</body>
</html>

VERY basic stuff. now, the php on the results page is this:


PHP Code:

<html>
<head><title>Your Query Results</title></head>
<body>
 <h2> Search Results</h2>
 <br>
 <?
 $link 
"<a href='searchbyname.html'> Back </a>";
 if (!
name){
  echo 
"Not Foumd";
  echo 
$link;
 exit; 
 }
    
$db mysql_connect("localhost");
    
mysql_select_db("kyleprolang"$db);
    
$query "SELECT languages.language FROM languages WHERE language LIKE '%".$name."%'";
    
$result mysql_query($query);
    while (
$record mysql_fetch_assoc($result)){
 while(list(
$fieldname$fieldvalue) = each($record)){
  echo 
$fieldname.": <br>".$fieldvalue."</b><br>";
 }
 echo 
"<br>";
 }
 
?>
</body>
</html>
I know that problem in the PHP script is where it says:

PHP Code:

 $query "SELECT languages.language FROM languages WHERE language LIKE '%".$name."%'"
i don't know what to put there. i want php to search the entire database. the databse is as followed:

Name: kyleprolang

Tables:

1) Languages
2) Power

Languages:

+--------------+------------+--------------+
| Language | Difficulty | Fun_Level |
+--------------+------------+--------------+
|_________|_________|_________| }
|_________|_________|_________| }
|_________|_________|_________| values and stuff
|_________|_________|_________| }
|_________|_________|_________| }
|_________|_________|_________|



Power:

+--------------+------------+
|Number |Language|
+--------------+------------+
|_________ |________|
|_________ |________| } values and stuff

i want PHP to search through the entire database and echo the results. how would i have PHP search through the entire data base in the "$query =" line?
Reply With Quote