search php mysql

starview
starview used Ask the Experts™
on
Maybe someone can tell me if there is a php search script out there that I can use or change that will do the following

search my mysql database by keywords in a data field and
echo out the names.

database "starview_view" username = "root" password ""
these are not the ones I use.

Table = cue_sheets
field = dance_name
field = rhythm
field = phase
field = choreographer
field = pdf_file

The field name  I would be search would be dance_name
when found,  it would echo out all the fields connected to this search like.

Dance Name  Rhyththm choreographer pdf files




Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You could write the  following query

$sqlQuery = "SELECT dance_name, rhythm, phase, choreographer,pdf_file FROM cue_sheets where dance_name like '%".$searchparam."%' ";

$result = mysql_query($sqlQuery);

$data = mysql_fetch_array($result);

foreach($data as $record){
     echo $record['dance_name']."</br>";
     echo $record['rhythm']."</br>";
     echo $record['phase']."</br>";
     echo $record['choreographer']."</br>";
     echo $record['pdf_file']."</br>";
}



thanks

kalpan

Author

Commented:
I am not sure how to use this, my skills in php and mysql are very limited

Thank you
you can copy the below attached code and save as test.php

you can access this with ur webserver on browser like http://localhost/test.php?dn=rock

make sure the database, table name and the mysql connection as per your settings in the file....


Thanks

Kalpan



$host = 'localhost';
              	$user = 'root';
                $pass = 'XXXXX';
                $db = 'temp1';

                $link = mysql_connect($host,$user,$pass);
                if(!$link)
                        die('Could not connect to mysql dadtabase'.mysql_error());

                $condb = mysql_select_db($db,$link);
                if(!$condb)
                        die('Could not select the temp1 Database:'.mysql_error());

$sqlQuery = "SELECT dance_name, rhythm, phase, choreographer,pdf_file FROM cue_sheets where dance_name like '%".$searchparam."%' ";

$result = mysql_query($sqlQuery,$link);

$data = mysql_fetch_array($result);

foreach($data as $record){
     echo $record['dance_name']."</br>";
     echo $record['rhythm']."</br>";
     echo $record['phase']."</br>";
     echo $record['choreographer']."</br>";
     echo $record['pdf_file']."</br>";
}

?>

Open in new window

PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Author

Commented:
When I run this all I get is.

I
I
I
I
T
T
T
I
I
I
I
R
R
R
R
Also I don't see anywhere where you can enter your search Query of what a person is looking for?
you can changes the

SELECT dance_name, rhythm, phase, choreographer,pdf_file FROM cue_sheets where dance_name like '%".$searchparam."%'

to perform which field you need to search on

do the print_r($data); after $data = mysql_fetch_array($result);

see what values you are getting....do the follwoing to maniuplate the array and get the appropriate value

foreach($data as $record){
     echo $record[0]."</br>";
     echo $record[1]."</br>";
     echo $record[2]."</br>";
     echo $record[3]."</br>";
     echo $record[4]."</br>";
}



Author

Commented:
I have a script that I have found and it seems to do all most all of what I want it to do except:
 I would like to see if is possible to add the following:

When the search finds its query i would like it to echo out the all fields that belong to that query:
sample if the search was "Roses are blue" that it would echo out the following fields:
dance_name = Roses are blue
rhythm = Two Step
phase = II
choreography = Jone Doe
pdf_file = Roses are blue.pdf

I have attach the code
<html><head></head>
<?php
$connect=mysql_connect("localhost","xxxxxx","xxxxxxx"); // Establish a connection 
mysql_select_db('xxxxxxx',$connect); // Name of your DB 

if(!$connect) // If connection not established 
print 'Could not connect to the database'; // Show an error 

if(isset($_GET['search'])) // If it's submitted 
{ 
$inp = Clean($_GET['inpname']); // Clean my input 
$query="SELECT dance_name, rhythm, phase, choreographer,pdf_file FROM cue_sheets where dance_name like '%$inp%' "; // mySql query 

$r = mysql_query($query) or die(mysql_error()); // If query fail, let me know the error 
if(mysql_affected_rows()===0) // If no match found 
echo "{$inp} is not in our database."; // Let me know it is'nt found in the table 
else 
{ 
echo "<p>{$inp} was successfully searched.</p>"; // Yes, the query worked 
while($row=mysql_fetch_array($r)) // Loop through the query results 
echo "{$row[0]}<br>"; // Show the results
 
} // End of the else statement 
} // End of the if statement 

function Clean($str) // Clean my input 
{ 
return mysql_real_escape_string(strip_tags(trim($sStr))); 
}
?>
<body>
<form name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input name="inpname" type="text">
<input type="submit" name="search" value="Search">
</form>
</body></html>

Open in new window

Author

Commented:
Thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial