Jump to content

create a very very simple search form


davids_media

Recommended Posts

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
Share on other sites

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