hi frnds,
i am doing a project related to food items..
here i took different categories like restaurants,pubs,foodfestivals,hangouts...
and also i took diffrent tables for each category in database..
each table having area,rname...now i need to search what ever user typed in textbox(area,rname) from database.
plz give any suggestions asap..

Recommended Answers

All 3 Replies

This is only from the top of my head but if what you place in those 2 fields (area, rname) need to match percisely what are in those 2 columns within the mysql database then you could use something along the following:

<?
//mysql connections
if (isset($_POST['area']) && isset($_POST['rname']))
    {
    $result=mysql_query("SELECT * FROM `table` WHERE `area`='".$_POST['area']."' AND `rname`='".$_POST['rname']."'");
    echo "<table border=1 cellpadding=4 cellspacing=0><tr><td>area</td><td>rname</td><td>column3</td></tr>";
    while ($rowid=mysql_fetch_array($result))
        {
        //perform actions for earch row found
        echo "<tr><td>".$rowid['area']."</td>";
        echo "<td>".$rowid['rname']."</td>";
        echo "<td>".$rowid['column3']."</td></tr>";
        }
    echo "</table>";
    }
?>

<form method='post'>
area=<input type='text' name='area'><br>
rname=<input type='text' name='rname'><br>
<input type='submit' value='submit'>
</form>

Hi...
What i suggest you is to create a category select box and its value should be the same as of your tablename.... (this is what you have done.. table for every category)

I hope too many php tags doesn't confuses you... Its just to display result in a better way...

<?php

if(isset($_POST['submit']))
{
	
	$sql="Select * from ".$_POST['category']." where area like '%".$_POST['area']."%' and rname like '%".$_POST['rname']."%' order by area asc";
	$result = mysql_query($sql);

?>
	<table border="1">
		<tr>
			<td colspan="2"> Search in table >> <?php echo $_POST['category']; ?></td>
		</tr>

<?php
	if(mysql_num_rows($query) > 0)
	{
		while($row = mysql_fetch_array($result))
		{
?>
		<tr>
			<td>$row['area'];</td>
			<td>$row['rname'];</td>
		</tr>
<?php
		
		}
	}
	else
	{
?>
		<tr>
			<td colspan="2">No entry found</td>
		</tr>
<?php

	}
?>

	</table>
<?php
}

?>



<form name="form_search" method="post" action="">
	Select Category <select name="category">
				<option value="restaurants">Restaurants</option>
				<option value="restaurants">Restaurants</option>
				<option value="restaurants">Restaurants</option>
				<option value="restaurants">Restaurants</option>
			</select>
	<br/>
	Area <input type="text" name="area" id="area" />
	<br />
	Rname <input type="text" name="rname" id-"rname" />
	<br />
	<input type="submit" value="search" name="submit">
</form>

1; set $searchResult= array();

2; Check each tables and push all results to the array $searchResult, like below

$sql="SELECT   *  FROM    df_restaurent WHERE  (df_restaurent.Address  LIKE '%$query1%' )  GROUP BY RestaurentId ;";

                   $result=$this->db->query($sql);
                   $data=$this->db->fetchAll($result);
                   foreach($data as $dd)
                     {      
                 array_push($searchResult, array( "Page" => "RestaurentDetails", "RestaurentId"=>"$dd->RestaurentId" ));

                     }

3; At the end of cheking of all tables , return $searchResult

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.