Jump to content

How write php for a search form?


usman07

Recommended Posts

how difficult is it to a search form with the image i shown?

 

From the looks of your questions I would say very.

 

If you have done a login system then you have already worked with forms and databases (hell, you've even had to search the database for a specific user already). Why not try and apply that same knowledge to a different problem?

Link to comment
Share on other sites

im surprised there is not any real tutorials online.

 

There would be literally thousands of tutorials around that show you how to display data from a database. ANyway, why not make a start by simply posting a search term to a php script and have the php script send that term to the database? See if you can get some results in an array. Once you have that, see if you can loop through that array and display it's data on a web page.

Link to comment
Share on other sites

Am i on the right lines with the php code for a search form? basically i want data from the mysql database to output and show on the website depending on what the users search is. (im new to php)

 

<?php
$username="";
$password="";
$database="";

mysql_connect("","","");
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM tablename";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;
while ($i < $num) {

$field1-name=mysql_result($result,$i,"id");
$field2-name=mysql_result($result,$i,"Location");
$field3-name=mysql_result($result,$i,"Property type");
$field4-name=mysql_result($result,$i,"Number of bedrooms");
$field5-name=mysql_result($result,$i,"Purchase type");
$field6-name=mysql_result($result,$i,"Price range");

echo "<b>$field1-name 
$field2-name2</b><br>$field3-name<br>$field4-name<br>$field5-name<hr><br>";

$i++;
}

?>

 

Link to comment
Share on other sites

You need to pass the data a user submits through the form into a WEHRE clause in your query. Other than that, yeah, that is one way to display results from a database query.

 

It's not the cleanest of most common way however. Take a look at mysql_fetch_assoc and the examples of it's usage.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.