davids_media Posted May 4, 2012 Share Posted May 4, 2012 I am currently looking to have two pages, one with a search form (textbox and button) and output the results (from database table) based on the strings input to another page. how do i achieve this? i just want something very simple nothing too complex and advanced please Link to comment https://forums.phpfreaks.com/topic/262085-create-a-very-very-simple-search-form/ Share on other sites More sharing options...
dmikester1 Posted May 4, 2012 Share Posted May 4, 2012 Do you have some starting code to help us out? I don't think many people here are willing to write the whole thing for you. Link to comment https://forums.phpfreaks.com/topic/262085-create-a-very-very-simple-search-form/#findComment-1343146 Share on other sites More sharing options...
davids_media Posted May 4, 2012 Author Share Posted May 4, 2012 not at the moment all i have is the home page where users will search from: <?php $title = 'Home'; error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require_once ('includes/config.inc.php'); require_once (MYSQL); include ('./includes/header.html'); include ('./includes/main.html'); ?> <div id="right"> <form id="frmSearch" method="post" action="result.php"> <input type="text" name="search" value="Search for a product..." onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" id="txtSearch" /> <input type="submit" name="submit" value="Search" id="btnSearch" /> </form> <?php ?> <br /> <div id="shop"> <div class="shoprow"> <div class="shopcell"> <img src="includes/inc_pics/SCRUNCHIES.jpg" width="100" height="100" /> <div class="shopsubcell"> <li><a href="cat.php?catID=1">Human Hair</a></li> </div> </div> <div class="shopcell"> <img src="includes/inc_pics/SCRUNCHIES.jpg" width="100" height="100" /> <div class="shopsubcell"> <li><a href="cat.php?catID=2">Pony Tails</a></li> </div> </div> <div class="shopcell"> <img src="includes/inc_pics/SCRUNCHIES.jpg" width="100" height="100" /> <div class="shopsubcell"> <li><a href="cat.php?catID=3">Scrunchies</a></li> </div> </div> </div> <br /> <div class="shoprow"> <div class="shopcell"> <img src="includes/inc_pics/SCRUNCHIES.jpg" width="100" height="100" /> <div class="shopsubcell"> <li><a href="cat.php?catID=4">Full Heads</a></li> </div> </div> <div class="shopcell"> <img src="includes/inc_pics/SCRUNCHIES.jpg" width="100" height="100" /> <div class="shopsubcell"> <li><a href="cat.php?catID=5">Synthetic Hair</a></li> </div> </div> <div class="shopcell"> <img src="includes/inc_pics/SCRUNCHIES.jpg" width="100" height="100" /> <div class="shopsubcell"> <li><a href="cat.php?catID=6">Accessories</a></li> </div> </div> </div> <br /> <div class="shoprow"> <div class="shopcell"> <img src="includes/inc_pics/SCRUNCHIES.jpg" width="100" height="100" /> <div class="shopsubcell"> <li><a href="cat.php?catID=7">Contact Lenses</a></li> </div> </div> <div class="shopcell"> <img src="includes/inc_pics/SCRUNCHIES.jpg" width="100" height="100" /> <div class="shopsubcell"> <li><a href="cat.php?catID=8">Lip Tattoos</a></li> </div> </div> </div> </div> </div> <?php include ('./includes/footer.html'); ?> and the result.php (which is almost redundant at the moment: <?php $title = "Pick your Product"; //Set number of columns to use $maxCols = 3; error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require_once ('./includes/config.inc.php'); require_once (MYSQL); include ('./includes/header.html'); include ('./includes/main.html'); { //Create and run query to get product category names for the selected cat ID $query = "SELECT `product`.`prodID`, `product`.`product`, `category`.`cat`, `product`.`prod_descr`, `category`.`cat_descr`, `product`.`price`, `product`.`image`, `product`.`stock` FROM `product` LEFT JOIN `category` ON `product`.`catID` = `category`.`catID` WHERE `product`.`product` LIKE 's%' ORDER BY `product`.`product`"; $r = mysqli_query($dbc, $query); $showHeader = true; echo "<div id='right'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { echo "<table class='table-container'>"; $showHeader = false; //Set index var to track record count $recIdx = 0; $recIdx++; //Open new row if needed if($recIdx % $maxCols == 1) { echo "<tr>"; } } //Display product echo "<td>"; echo "<img src='db/images/".$row['image']."' height=150px width=150px /><br>"; echo "<li>" . "<a href='item.php?prodID={$row['prodID']}' title='{$row['product']}'>" . $row['product'] . "</a>" . "</li>"; echo "<span>" . "£". $row['price'] . "</span>"; echo "<li>" . $row['cat'] . "</li>"; if ($row['stock'] < 2) // If there less than two items in stock!! { echo " (<span> Low in Stock! </span>) "; } elseif ($row ['stock'] = 0) { echo "Sorry, currently not available but we will try hard to get more in!"; } echo "</td>"; //Close row if needed if($recIdx % $maxCols == 1) { echo "</tr>"; } } //Close last row if needed if($recIdx % $maxCols == 0) { echo "</tr>"; } //Close table & div } echo "</table>"; echo "</div>"; include ('./includes/footer.html'); ?> note in the query code for the SQL I have made use of the LIKE operator (WHERE product LIKE '$'). Link to comment https://forums.phpfreaks.com/topic/262085-create-a-very-very-simple-search-form/#findComment-1343154 Share on other sites More sharing options...
downah Posted May 5, 2012 Share Posted May 5, 2012 use the $_POST function, select from your database based on the search string Link to comment https://forums.phpfreaks.com/topic/262085-create-a-very-very-simple-search-form/#findComment-1343390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.