Jump to content

Need Help - Best Practice for handling search output


Haighy
 Share

Recommended Posts

Hi All Firstly, let me set the describe what i am trying to do: I have a php website which takes in a parameter(product) provided by the user via form. The php makes a request to a series of providers and gets back xml (details of the product). Currently i parse the xml and load it into an array which i then display on the screen via an html table. This works fine but is quite basic in terms of the offering to the user. Ideally i want the user to be able to filter or sort the results ( by price, by retailer, by relivance etc.. ). This presents me with a few challenges so am turning to this audience to steer me in the right direction hopefully :) .. If i continue using the array approach, from my level of experience (which is not good) it looks like i will have reload the php page by passing new parameters needed for the filtering/sorting and then make all the necessary requests again. To me this does not seem very efficient I was wondering whether the results of the requests could be stored into a session linked temporary table in a database and therefore filtering and search is easier and more flexible while only making the data request once from source. I know how to use tables but have no experience in temporary tables so not even sure if this is viable. volume of requests are low but needs to be a little scalable - doubt i will much intial traffic once up and running :)please help

Edited by Haighy
Link to comment
Share on other sites

Add those options to your display (price, available discount, size, etc) when you display the results and use javascript to reorder the results if you want the user's computer to do most of your work. EDIT: Don't forget to follow your topic (see upper right).

Edited by niche
Link to comment
Share on other sites

how your data is stored? is it any providers API call which returns XML file or it is a database? If it is database you can sort or filter using "ORDER BY" and "WHERE" clause. but in this case you need to make a request to php file each time. if you want it to do dynamically you can use AJAX with that. but still it will send a request evrytime to your server. if it is xml file you can also use XPATH to filter out data from XML documentResource:http://php.net/xpathhttp://w3schools.com/xpath If it is not an API returned XML file and data is arbitary and large and it is possible for you to use any database, sthen database will be better option for this. as databases are optimised for this kind of sorting and filtering. otherwise you have to implement those on your own to get that level of efficiency. Also if it is API call from 3rd party server it is best to cache it in your server in any persistent storage rather than calling their API every time. If you are worried about performance you can use memcache which can cache results to reduce database hit.

Link to comment
Share on other sites

The data size is not an issue at this stage and the 3rd party returns XML output so it just a case of stripping out the necessary items and displaying the data and being able to filter At the momment i load into a 2 dimension array - which can be sorted but requires the api call each time which is where i think i am not being efficient 3 interesting points made above:

  1. If i used javascript to sort/ order i am assuming i will still need to make the api request each time - or not ( i don't know much about this topic as am not very experienced )
  2. The caching sounds like a really good idea so will look at the memcache link
  3. In terms of database, i could use it but the tables should be tempoary and again not sure how to do that

Link to comment
Share on other sites

to add a bit more detail - i want to present the data in a default fashion and display it. but, then allow the user to re-order and filter based on price, relivance, retailer etc so the page i guess will need to be reloaded? again seeking help the webpage is www.tradingbay.co and the section i am talking about is how to handle the search results - this website is still very much under construction so some of the links don't work :)any feedback would be well received

Link to comment
Share on other sites

There is no right way of handling search results. Ideally, describe how you think your users want their info in four sentences or less.

Link to comment
Share on other sites

why do you think you need a temporary table in database? you can store the data in table when user request a product first time. everytime user request same product you will query the db if product exist fetch and serve it else get XML from 3rd party populate db and show it to user. after you store them in database the filtering the result is trivial (using WHERE clause to limit the result) but yes that would need a ajax call to do it dynamically. if you do that in js you dont need to recall the api if you are getting the super set of the data. you can filter it dynamically. best way depends on the structure of data which you will recive and work on.

Link to comment
Share on other sites

entry pointuser enters a string ' ie coffee machine' default display should show

  • show all retailer prices grouped by the product title (ordered cheapest first)
  • all product titles are ordered by relivance ( an internally generated rating based on product title & description in relation to search string)

The user should then be able to

  • only show products within a price brand
  • only show products against a specific retailer
  • choose how many items are displayed on screen ( default is all)
  • possibly order the product titles by A-Z / Z-A or back to 'by relivance'

all can be achieved by reloading the output page with different params but this will recall the api request In terms of data referece i use an array ( actually 3 dimensional ) Array [ Producttitle] = array [ Retailer ] = array [Price ] =valueArray [ Producttitle] = array [ Retailer ] = array =value

Link to comment
Share on other sites

Are you or are not able/ready to use a database? I skimmed the previous posts and couldn't tell.

Edited by niche
Link to comment
Share on other sites

Compared to what? The footprint of a database is integrale to your site once you've chosen to use one. To be sure there are other ways to to maintain data, but they are mostly (probably exclusively) short term. At least for now. If you agree, what do you want to call your database?

Edited by niche
Link to comment
Share on other sites

ok you've sold methat way i can keep track of what searches are being performed - apart from that i don't need to keep the information say after a week/month so when someone conducts a search, i check the database for the search string. If it does not exist, i then call the API to get it.if the user decides so sort/filter it is a fair assumption that it will be in the database but will put in a catch just in case many, many thanks for your time - now i need to learn the db handling logic :)

Link to comment
Share on other sites

Please do that by doing. Do/review the w3schools php and sql tutorials, but be careful not to put too much time into learning it before you use it. Learn enough to ask informed questions THEN START POSTING YOUR CODE with your questions! No one here is going to chide you for earnest work at this forum. Your will tell us if you're working hard or hardly working.

Link to comment
Share on other sites

The opportunities to get side tracked are infinite. Getting off task is one of the biggest challenges (maybe the biggest) to self learning IMO.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...