hi everyone,
I need someone to give me a little direction. Below I have the code that I am trying to understand . But because I am so new to mysql I am having trouble. This script is suposed to do a search on the database. But I am getting loss in the code any help would be great?
I have written the question I have and the code under neath.
gishaust
Q1.Is the will the following code allowing me to access the the database I have designed?
$host=‘localhost′;
$name=‘server’;
$pass=‘zxcv’;
$sname = ‘custom’;
mysql_connect ($host, $name, $pass);
mysql_select_db($sname) or die(‘Cannot select database’);
Q2. This recieves get variable that comes from the form on this script and pass it onto the
search variable is that right?
if(isset($_GET[’search’]))
{
$search = $_GET[’search’];
}
Q3. I can't work this out why do I need to explode something to search if I want to pass the variable to $keywords. Why don't i $keywords = $search;?
$keywords = explode(" ", $search);
Q4.
The if statement is to see if $search has something in the string but what is % in there for?
$query is searching the database is that right?
The select is looking at the table called customerss in the database I have connected too?
"WHERE column1 LIKE ‘%".$keywords[$i]."%’". I have no idea!!!
if ($search == NULL or $search == ‘%’){} else {
for ($i=0; $i<count($keywords); $i++) {
$query = "SELECT * FROM customerss " .
"WHERE column1 LIKE ‘%".$keywords[$i]."%’".
" OR column2 LIKE ‘%".$keywords[$i]."%’" .
" OR column3 LIKE ‘%".$keywords[$i]."%’" .
" OR column4 LIKE ‘%".$keywords[$i]."%’" .
" ORDER BY column1";
}
$result = mysql_query($query) or die(mysql_error());
}
This form is so I do the search on the database?
echo "<br /><form name='searchform' method='GET' action='".$_SERVER['PHP_SELF']."'>";
echo "<input type='text' name='search' size='20' TABINDEX='1' />";
echo " <input type='submit' value='Search' />";
echo "</form>";
If this is all correct how do I get it to show on the page?