Jump to content

probir

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

probir's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. finally i have solved my problem myself with a simple tricks given from my friend.
  2. i forget to give the searchform.php here it is.. and the $text define this form <form action="searchresult.php" method="get"> <div align="center"> <p> <input name="search" type="text" size="30"/> <input name="submit" type="submit" value="Search" /> </p> </div> </form>
  3. hi i am new in here and php coding. i got the following code frm my friend for making a name, address, passout of student searching database. <?php // TAKE THE INFORMATION FROM FORM. $search = $_GET['search']; // IF THERE IS NOT A KEYWORD GIVE A MISTAKE. if (!$search) echo "You didn't enter a keyword."."$text Back to Search Again <a href=searchform.php>Search</a>"; else { echo "<td>You searched for: <strong>$search </strong></td>"; mysql_connect('sql servername','sql server username','password'); mysql_select_db('database name'); $id=@$_GET['id']; //QUERY IS THE CODE WHICH WILL MAKE THE SEARCH IN YOUR DATABASE. //I WROTE AN EXPLANATION ABOUT IT AFTER THE CODE. $query="SELECT * FROM searchform WHERE MATCH(Name, Address, Pass) AGAINST('%$search%' IN BOOLEAN MODE)"; $result1 = MySQL_query($query); if(!$result1) { echo MySQL_error()."<br>$query<br>"; } if(MySQL_num_rows($result1) > 0) { echo "<table width='480' align='center' border='1' cellspacing='0' cellpadding='0'>"; while($result2 = MySQL_fetch_array($result1)) { //A short description from category. $description = $result2['category']; $searchPosition = strpos($description, $search); $shortDescription = substr($description, $searchPosition, 150); // I added a link to results which will send the user to your display page. echo "<tr><td>Name</td><td>Address</td><td>Pass</td></tr>"; echo "<tr><td>{$result2['Name']}</td><td>{$result2['Address']}</td><td>{$result2['Pass']}</td></tr>"; } echo "</table>"; }else { echo "No Results were found.<br>"."$text Back to Search Again <a href=searchform.php>Search</a>"; }echo "<br>"; } ?> every thing is working fine as i wanted. my database structure is below |NAME||ADDRESS||YEAR| |ABC|abc|1980| |XYZ||xyz||1980| but there is a small problem of showing the output result. when i search with 1980 it show 4 column 1st column is showing NAME, ADDRESS, YEAR 2nd column is showing |ABC|abc|1980| again 3rd column is showing NAME, ADDRESS, YEAR 4th column is showing |XYZ||xyz||1980| how i solve to not showing every column the NAME, ADDRESS, YEAR (3rd column)
  4. i am try to make a name, address search system into my website from my database. but i got this msg [Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampplite\htdocs\3\searchresult.php on line 54] my full php code i.e. searchresult.php is under...... what i have mistake..... searchresult.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php // TAKE THE INFORMATION FROM FORM. $search = $_GET['search']; // IF THERE IS NOT A KEYWORD GIVE A MISTAKE. if (!$search) echo "You didn't enter a keyword"; else { echo "<td>You searched for: <strong>$search </strong></td>"; mysql_connect('localhost','root',''); mysql_select_db('search'); $id=@$_GET['id']; //QUERY IS THE CODE WHICH WILL MAKE THE SEARCH IN YOUR DATABASE. //I WROTE AN EXPLANATION ABOUT IT AFTER THE CODE. $sql = "CREATE TABLE searchform \n" ."(\n" ."ID int NOT NULL AUTO_INCREMENT ,\n" ."FirstName varchar( 255 ) NOT NULL ,\n" ."LastName varchar( 255 ) NOT NULL ,\n" ."Email varchar( 255 ) NOT NULL ,\n" ."PhoneNumber varchar( 255 ) NOT NULL ,\n" ."PRIMARY KEY ( ID ) )";; $result1 = MySQL_query($query); if(!$result1) { echo MySQL_error()."<br>$query<br>"; } if(MySQL_num_rows($result1) > 5) { echo "<table width='750' align='center' border='0' cellspacing='0' cellpadding='0'>"; while($result2 = MySQL_fetch_array($result1)) { //A short description from category. $description = $result2['category']; $searchPosition = strpos($description, $search); $shortDescription = substr($description, $searchPosition, 150); // I added a link to results which will send the user to your display page. echo '<tr><td><p><strong><a href="displayresults.php?id='.$result2['id'].'">'.$result2['title'].'</strong></p></td></tr>'; echo "<tr><td>$shortDescription ...</td></tr>"; echo "<td>{$result2['name']} {$result2['surname']}</td><tr/>"; } echo "</table>"; }else { echo "No Results were found in this category.<br>"; }echo "<br>"; } ?> </body> </html> and searchform.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form action="searchresult.php" method="get"> <div align="center"> <p> <input name="search" type="text" size="60"/> <input name="submit" type="submit" value="Search" /> </p> </div> </form> </body> </html>
×
×
  • 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.