| |
|
Welcome to KnowledgeSutra - Dear Guest | |
How To Make A Search Form And Php Code?
#11
Posted 08 September 2008 - 02:43 AM
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
#13
Posted 10 November 2009 - 03:12 AM
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
Posted 18 November 2009 - 06:26 PM
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_*
Posted 16 September 2010 - 11:17 PM
arcticsnpr, on 21 April 2006 - 04:49 AM, said:
in Christ, arctic
#16 Guest_mujeeb_*
Posted 06 August 2011 - 09:00 PM
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_*
Posted 20 September 2011 - 10:52 AM
arcticsnpr, on 20 April 2006 - 11:15 PM, said:
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
, 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
#18 Guest_pooja_*
Posted 23 March 2012 - 03:42 PM
<?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
Posted 24 March 2012 - 10:46 AM
pooja, on 23 March 2012 - 03:42 PM, said:
<?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).
Reply to this topic

1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users















