Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9204505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:43:33+00:00 2026-06-17T23:43:33+00:00

I have MySQL table called products and in this table I have data: id

  • 0

I have MySQL table called products and in this table I have data:

id | category | product1 | price1 | discount1 | product2 | price2 | discount2 | product3 | price3 |discount3 |
----------------------------------------------------------------------------------------------------------
| 1 | Meat    | Pork 1kg | 3.99   | -30%    | Lamb 1kg    | 5.94 | -25%      | Ham 200g    | 1.99 | -10% |
| 2 | Fruit   | Apple 1kg| 1.25   | -32%    | Banana 1 kg | 0.99 | -15%      | Melon 1 kg  | 0.79 | -12% |

PHP search script I have looks like this:

//-query the database table
$sql="SELECT id, category, product1, price1, discount1, 
product2, price2, discount2, product3, price3, discount3 
FROM products 
WHERE 
product1 LIKE '%" . $name . "%' OR 
price1 LIKE '%" . $name ."%' OR 
discount1 LIKE '%" . $name ."%' OR 
product2 LIKE '%" . $name ."%' OR 
price2 LIKE '%" . $name ."%' OR 
discount2 LIKE '%" . $name ."%' OR 
product3 LIKE '%" . $name ."%' OR 
price3 LIKE '%" . $name ."%' OR 
discount3 LIKE '%" . $name ."%'";

//-run the query against the mysql query function
$result=mysql_query($sql);

//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){

$id=$row['id'];
$category =$row['category'];
$product1=$row['product1'];
$price1=$row['price1'];
$discount1=$row['discount1'];
$product2=$row['product2'];
$price2=$row['price2'];
$discount2=$row['discount2'];
$product3=$row['product3'];
$price3=$row['price3'];
$discount3=$row['discount3'];

//-display the result of the array

echo "<ul>\n"; 
echo  "<li>" . $id . "</li>\n"; 
echo "<li>" . $category . "</li>\n";
echo "<li>" . $product1 . "</li>\n"; 
echo "<li>" . $price1 . "</li>\n";
echo "<li>" . $discount1 . "</li>\n";
echo "<li>" . $product2 . "</li>\n";
echo "<li>" . $price2 . "</li>\n";
echo "<li>" . $discount2 . "</li>\n";
echo "<li>" . $product3 . "</li>\n";
echo "<li>" . $price3 . "</li>\n";
echo "<li>" . $discount3 . "</li>\n";
echo "</ul>";
}  

The problem is that when I search for let’s say Apple, Banana and Melon are also displayed.

How can I make it to show only Apple and it’s price and discount when searching with keyword apple.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:43:34+00:00Added an answer on June 17, 2026 at 11:43 pm

    Your DB structure is very odd, which is giving you this headache. Instead use normal relations.

    Table categories

    id  name
    1   Meat
    2   Fruit
    

    Table products

    id  category_id  product      price  discount
    1   1            Pork 1kg     3.99   -30%
    2   1            Lamb 1kg     5.94   -25%
    3   1            Ham 200g     1.99   -10%
    4   2            Apple 1kg    1.25   -32%
    5   2            Banana 1 kg  0.99   -15%
    6   2            Melon 1 kg   0.79   -12%
    

    You can find a product (eg ‘pork’) using this query

    SELECT product.*, category.name as category FROM product INNER JOIN category ON product.category_id = category.id WHERE product.name LIKE 'pork%'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql table called category Inside this table lets say i have
I have a MySQL table called category that holds hierarchical data as an adjacent
I have a MySQL table called accounts . Within this table is a field
I have this mysql table called comments which looks like this: commentID parentID type
I have a MySQL database table called Participant that looks something like this: (idParticipant)
I have a mysql table called RATING with this structure: ID, USERNAME, RATING, RATER,
I have a mySQL table called clients with this structure: Name | Phone |
I have a table called products in a MySQL database. products looks some what
I have a table called jobs in a MySQL database. One user adds data
I have a MySql table called reviews which stores a lot of product reviews,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.