Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

How To Make A Search Form And Php Code?


19 replies to this topic

#11 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 08 September 2008 - 02:43 AM

can you please make it more clear ?
How To Make A Search Form And Php Code?

Replying to arcticsnpr
Hi artisncr..

I read your html code and php code.
I am looking for a site search also..In my php website

Could you please make 123 step for search.Php?
1. Where / which directory to upload this code.
2. Do I have to change database username etc ?

How can I see my database name ?

And could you please tell how to make a home page that have a dynamically change news from other side ?

Thank you artist

#12 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 21 May 2009 - 10:11 AM

Display DataHow To Make A Search Form And Php Code?

Hi There,

I found the above script very usefull. I want to go one step further though...

I want to display a table with data based on the query. How do I do that??

Thanks in advance

Gert



#13 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 10 November 2009 - 03:12 AM

Pls Help me......... This code work from our local machine... i can put server that canHow To Make A Search Form And Php Code?
this code source...
<?php/*set varibles from form */$searchterm = $_POST['searchterm'];Trim ($searchterm);/*check if search term was entered*/If (!$searchterm){    echo 'Please enter a search term.';}/*add slashes to search term*/If (!get_magic_quotes_gpc()){$searchterm = addslashes($searchterm);}/* connects to database */@ $dbconn = new mysqli('localhost', 'root', '', 'sample1');If (mysqli_connect_errno()){Echo 'Error: Could not connect to database.  Please try again later.';Exit;}/*query the database*/$query = "select * from sheet1 where IndexNo like '%".$searchterm."%'";$result = $dbconn->query($query);/*number of rows found*/$num_results = $result->num_rows;echo '<p>Found: '.$num_results.'</p>';/*loops through results*/For ($I=0; $I <$num_results; $I++){$num_found = $I + 1;$row = $result->fetch_assoc();Echo "$num_found. ".($row['IndexNo'])." <br />";Echo "<table border='1'><tr><th>IndexNo</th><th>Name</th><th>Marks</th><th>Rank</th></tr>";  echo "<tr>";  echo "<td>" . $row['IndexNo'] . "</td>";  echo "<td>" . $row['Name'] . "</td>";  echo "<td>" . $row['Marks'] . "</td>";  echo "<td>" . $row['Rank'] . "</td>";Echo "</tr>";}Echo "</table>";/*free database*/$result->free();$dbconn->close();?>
-reply by Prashanth



#14 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 18 November 2009 - 06:26 PM

Real Estate WebsiteHow To Make A Search Form And Php Code?

I am making a real estate website and I have a search box. I want the buyers/sellers to be able to search for a home and however many bedrooms and bathrooms they want but I want the homes to pop up on my page. Does anybody have a code or a site to help me???? Any help is greatly appreciated. Thanks!!1



#15 Guest_Niki_*

  • Guests

Posted 16 September 2010 - 11:17 PM

Can you assist me with setting up the database that will be searched???? nicole.worthem@gmail.com


View Postarcticsnpr, on 21 April 2006 - 04:49 AM, said:

ok, I should have clarified if you knew very much stuff about this. I'll tell you what... I can't do it now (big chem test) but i'll hook you up with a search thing in no time. few questions. are you using mysql? do you have the whole Bible in it? I'm going to need your table structure, the way you built it (rows columns ect..) and.. when dealing with this kind of stuff, you really should use PHP 5, if your running the server, install it, trust me. if your not running a server and you have no choice... I'll see what I can do. But for now please supply with your table structure in your database. If you don't know what this is, research it. I'll code it, no worries.
in Christ, arctic


#16 Guest_mujeeb_*

  • Guests

Posted 06 August 2011 - 09:00 PM

Thanks for the codes.........

I tried the php code and it is showing like
[color=#FF0000]Fatal error: Call to a member function query() on a non-object in C:\wamp\www\student_database\php\search.php on line 20[/color]
please help me to correct this error.................

#17 Guest_paru_*

  • Guests

Posted 20 September 2011 - 10:52 AM

:)

View Postarcticsnpr, on 20 April 2006 - 11:15 PM, said:

aight, I made somthing to what I think your asking. If you go to the church site I made: CBF , it has a area where you can search for sermons in a database.
I'm thinking your using PHP 5.
aighy, here you go man... just wrote this up real quik for yu, very simple, hope it works for you :blink:
, Arctic

html form:
<html>
	<head>
		<title>Search Test</title>
	</head>
	<body topmargin="0" leftmargin="0">
		<form action="search.php" method="post">
			Search Term <input type="text" name="searchterm"><br />
			<input type="submit" value="Search">
		</form>
	</body>
</html>

php search.php:

<?php
/*set varibles from form */
$searchterm = $_POST['searchterm'];
trim ($searchterm);
/*check if search term was entered*/
if (!$searchterm){
	echo 'Please enter a search term.';
}
/*add slashes to search term*/
if (!get_magic_quotes_gpc())
{
$searchterm = addslashes($searchterm);
}

/* connects to database */
@ $dbconn = new mysqli('host', 'username', 'password', 'database'); 
if (mysqli_connect_errno()) 
{
 echo 'Error: Could not connect to database.  Please try again later.';
 exit;
}
/*query the database*/
$query = "select * from tablename where tablerow like '%".$searchterm."%'";
$result = $dbconn->query($query);
/*number of rows found*/
$num_results = $result->num_rows;

echo '<p>Found: '.$num_results.'</p>';
/*loops through results*/
for ($i=0; $i <$num_results; $i++)
{
 $num_found = $i + 1;
 $row = $result->fetch_assoc();
 echo "$num_found. ".($row['tablerow'])." <br />";
}
/*free database*/
$result->free();
$dbconn->close();
?>

oh, and your right, never alone with Christ, he reigns 4-ever
not bad :)

#18 Guest_pooja_*

  • Guests

Posted 23 March 2012 - 03:42 PM

hey how can we select only one row from the database dat matches with the entered text ?? plzz help...by writing this code m getting all d rows in the databse..plzz do the needfulll thankxxx..


<?php
$host="localhost";
$username="poojar";
$password="abc";
$database="allsites";

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$result = mysql_query("SELECT websitename,result FROM searchresult");

while($row = mysql_fetch_array($result))
  {
  echo $row['websitename'] ." " . $row['result'];
  echo "<br />";
  }
mysql_close();

?>

#19 rpgsearcherz

    Trap Double Mocha Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2,025 posts
  • Gender:Male
  • Interests:Working on my Rift fansite
  • myCENT:56.86
  • Spam Patrol

Posted 24 March 2012 - 10:46 AM

View Postpooja, on 23 March 2012 - 03:42 PM, said:

hey how can we select only one row from the database dat matches with the entered text ?? plzz help...by writing this code m getting all d rows in the databse..plzz do the needfulll thankxxx..


<?php
$host="localhost";
$username="poojar";
$password="abc";
$database="allsites";

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$result = mysql_query("SELECT websitename,result FROM searchresult");

while($row = mysql_fetch_array($result))
  {
  echo $row['websitename'] ." " . $row['result'];
  echo "<br />";
  }
mysql_close();

?>

Ah, your issue is that you have it set to "continue looping as long as there's more data." What you want to do is instead of have a while loop just erase the entire loop and output row 0 (which is really the first row).

#20 Guest_cibsrk_*

  • Guests

Posted 17 May 2012 - 03:27 PM

Great work!!

In my table I have 4 fields “First_name, Last_name, Phone_number, Affilation.
Is there any way to view all fields as search result?

Thanks for any help,



Cibsrk




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users