Skip to content Skip to sidebar Skip to footer

Php Website Search And Display Items

I am creating a dummy online store to illustrate some real world functionality which one of them is to search the website for items i.e. I have written PHP code to deal with this

Solution 1:

First, try removing this

while ($query_row = mysql_fetch_row($query_search)) 
                {
                    echo$query_row['product_name'];

                }

I also noticed a few bad typo in your code :

  • table id="display" an id should be unique. If you iterate over it and still want it to be an id, put display-n instead, n being the unique id of the product for example. (or use class="display" instead of id)

  • You should take a look at sql injection and how to defeat them.

Solution 2:

I might rather do this:

$query = "SELECT product_name FROM products WHERE product_name LIKE %" . $search . "%";

Hope it will help. Then use a foreach loop to run through the result like:

foreach ($searchas$key => $result){
      echo$result . '<br />';
}

Solution 3:

  1. mysql_fetch_row( $query_search) returns a plain array not an associative array but you are trying to access its values using keys - $query_row [ 'product_name' ]. Rather use _fetch_array

  2. There are lots of syntactical errors. There is a space between function name and list of parameters.

  3. Don't use mysql_. They are deprecated (read: dead). Use PDO instead.

Post a Comment for "Php Website Search And Display Items"