School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
You're Browsing As A Guest! Register Now...
Become an Expert!

Join 358,767 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,810 people online right now.Registration is fast and FREE... Join Now!



Return a best match from a database using PHP and SQLite

52 Weeks of Code Challenge: Android

Week #11 of the 52 Weeks of Code Challenge is Android, you should give it a shot. Click Here!

Return a best match from a database using PHP and SQLite Rate Topic: -----

#1 rjbzzr400  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 11-December 07


Dream Kudos: 0

Posted 14 March 2009 - 01:00 PM

Hi,

I have an access database in this format:

package_name  feature1  feature2  feature3
bronze			  yes		 no		  yes
silver				no		  yes		 no
gold				  no		  yes		 yes




and I have a webpage with a selection of drop down boxes that let the user
choose which features they require and when the form is submitted it communicates
with my database using SQLite.

Is there a way I can return the package from the database that matches
the majority of the user's selected requirements using PHP?

Thanks for any help :)
Was This Post Helpful? 0
  • +
  • -


#2 Auzzie  Icon User is offline

  • D.I.C Addict
  • Icon

Reputation: 38
  • View blog
  • Posts: 566
  • Joined: 20-January 09


Dream Kudos: 275

Re: Return a best match from a database using PHP and SQLite

Posted 14 March 2009 - 05:28 PM

http://uk.php.net/ma.../ref.sqlite.php not quite sure what your after so there
Was This Post Helpful? 0
  • +
  • -

#3 rjbzzr400  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 11-December 07


Dream Kudos: 0

Re: Return a best match from a database using PHP and SQLite

Posted 15 March 2009 - 05:03 AM

Once the user has selected which features they require (yes or no), I want to do a search on the databse that compares the user's requirements to each row and returns the row that matches exactly or has the majority of matches

Webpage with drop down boxes --> Query to database --> Return row that matches majority of answers

Basically I would like to know how to do a search, but if there is not a row that matches exactly, I want to return the row that matches the most fields. I can do an exact match search but not a partial match search.

Hope that makes sense :)
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is online

  • Dreaming Coder
  • Icon

Reputation: 631
  • View blog
  • Posts: 5,024
  • Joined: 16-October 07


Dream Kudos: 575

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

Re: Return a best match from a database using PHP and SQLite

Posted 15 March 2009 - 05:31 AM

Let's say I have tables that look like this:

Feature
	FeatureId
	Name

Package
	PackageId
	Name

PackageFeature
	PackageId
	FeatureId



It then becomes as simple as asking the database:
select PackageId, count(FeatureId) FeatureCount
	from PackageFeature
	where FeatureId in (2,3,4,6)
	group by PackageId
	order by count(FeatureId) desc



There are a number of ways to do this. A more elegant solution is to have a temp table with the user's list and do a join. It depends on the number of features you're looking at.

Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#5 rjbzzr400  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 11-December 07


Dream Kudos: 0

Re: Return a best match from a database using PHP and SQLite

Posted 15 March 2009 - 07:31 AM

View Postbaavgai, on 15 Mar, 2009 - 05:31 AM, said:

Let's say I have tables that look like this:

Feature
	FeatureId
	Name

Package
	PackageId
	Name

PackageFeature
	PackageId
	FeatureId



It then becomes as simple as asking the database:
select PackageId, count(FeatureId) FeatureCount
	from PackageFeature
	where FeatureId in (2,3,4,6)
	group by PackageId
	order by count(FeatureId) desc



There are a number of ways to do this. A more elegant solution is to have a temp table with the user's list and do a join. It depends on the number of features you're looking at.

Hope this helps.


Thanks for the reply I really appreciate it :), could you explain the above query a little more? What does FeatureCount relate to and what are the numbers 2,3,4,6 for? I understand each function in the query, but I don't fully understand it as a whole.
I have about 13 features in the table. Could I make a blank table with the same fields as the feature table and when the user submits the form could I insert the values (yes/no) into the new table and then do a count and join query? And if yes could you help me with that as I haven't done much with joins and the count function.

This post has been edited by rjbzzr400: 15 March 2009 - 07:32 AM

Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month