Jump to content

I need help with making Search for my page.


blodlesme

Recommended Posts

Hi guys , i am a newbie and i don't know much php , I'm folowing tutorials.

I want to make a search for my site and i read every tutorial that was on the net and i still don't get it.

I have 5 values in my dbase , id , name , name_2,value and pic_url , now i just want to search name and name_2 and then echo results, id value and pic_url.Can some one guide me trough that?

can you do mysql queries?

if not read up on how to do and display a mysql query here http://www.tizag.com/

now for the search you can use a query like

$query = "SELECT * FROM `table` WHERE `name` LIKE(\"%$search%\") OR `name_2` LIKE(\"%$search%\")";

 

Scott.

 

 

here is a basic search with very basic stuff and should be protected ageist all SQL injections

<?php
include "dbConnect.php";
if(isset($_GET['search'])){
$search = mysql_real_escape_string($_GET['search']);
$query = "SELECT * FROM `table` WHERE `name` LIKE(\"%$search%\") OR `name_2` LIKE(\"%$search%\")";
$result = mysql_query($query) or die(mysql_error() . "<br>" . $query);
if(mysql_num_rows($result) == 0){
	echo "No results returned";
}else{
	echo "<table>";
	while($row = mysql_fetch_assoc($result)){
		echo "<tr><td>{$row['id']}</td><td>{$row['value']}</td><td>{$row['pic_url']}</td></tr>";
	}
	echo "</table>";
}
}
?>
<form method=get>
<input type="text" name="search" value="<?=$_GET['search']?>" /><input type="submit" value="Search" />
</form>

 

it would proberly need some work but it shows a basic search function

 

Archived

This topic is now archived and is closed to further replies.

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