Jump to content

Recommended Posts

Hi there.

 

I am trying to implement a simple search system for my web.

 

When the user inputs some text into a search box then mysql starts querying the database.

 

Example:

<?php $query2 = mysql_query("SELECT * FROM products WHERE product_name = '$search'");
while ($row = mysql_fetch_assoc($query2))
{
$product_name = $row['product_name'];
echo $product_name;
} ?>

 

So i my question would be: how to return a line which says "no results were found" if the keyword does not mach anything from the db.

 

Thanks:)

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/259527-search/
Share on other sites

I've found a solution. Anyway there's another question on my mind. I only get the exact results from my search.

 

For example if i type in 'samsung galaxy tab' to my seach box, i get back 'samsung galaxy tab'.

 

However it would be great to be able to type in 'samsung galaxy' and get a back 'samsung galaxy tab' (at the moment i get no results).

 

How can i sort this out?

 

Thanks:)

 

EDIT:

I've done it by using LIKE

Link to comment
https://forums.phpfreaks.com/topic/259527-search/#findComment-1330358
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.