-
PHP (
http://www.daniweb.com/forums/forum17.html)
| sarithak | Dec 1st, 2008 1:29 am | |
| search from database 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.. |
| cwarn23 | Dec 1st, 2008 2:05 am | |
| Re: search from database 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> |
| sikka_varun | Dec 3rd, 2008 2:18 am | |
| Re: search from database 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> |
| All times are GMT -4. The time now is 10:28 am. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC