How to auto categorise user generated content - php

I have a system where the user makes a post, this post will include a title, and the post content itself, the content will be anywhere between 20 - 3000 words and consist of plain text.
I also have a set of more then 700 categories, some are top level categories, the rest are subcategories.
When the user enters the content for their post, they need to be prompted with up to 5 relevant categories, selected automatically based on what the user has typed in.
What is the best way to do this, I am using PHP & MySQL, links to any libraries or code samples would be useful.

User perspective
You cannot do this on 1 step in the same page with only php/mysql. There are mainly 2 options for your question.
You also learn/use some client-side language and implement it to do a search without changing the page. I don't know much of it, so I cannot really recommend anything specific, but this thread should help you.
You use a middle page. That said, the user posts it's content, then after sending it you parse it and offer categories for the user to select in the new page. This has the problem that many users might close the window after pressing 'send' in a comment as they expect it to be sent straight, the good thing is that it only uses php/mysql.
Parsing the text
Once again I'm not sure if this is the most efficient way, but I'd try this and keep testing until achieving the result expected:
First, create a list of few keywords for each category. 4 or 5 should do the trick, but it depends greatly on the categories, text and many other factors.
Then, create an array of 10 elements. 5 would be the id of the category and 5 would be the 'score' for each category. You can set, for example, a score of 1 for each keyword found. Remember to asign some values initially or you'll have nothing to compare it to.
Then I'd search each category keywords in the text. If you get an score superior than any of those obtained previously, substitute the minimum one for the new category.
Echo the 5 categories remaining at the end of the script. They should be the 5 more suitable. But keep in mind that there are many more ways to approach this parsing problem.

Related

Creating x amount of pages equal to x ID's in database?

The title may be a little vague, but I'll try to explain the concept here.
I have a site in which daily new items ( sports games ), get published, now what I would love is that my users would be able to click on a certain game and get redirected to a new page with more detailed information about that one game.
The thing is, creating every php page seperate for every game each day is a lot of work because also a lot details in the page need to be changed.
Now I was wondering if it is possible in some kind of way that there's a script that reads, OK you have 5 games today, page 1 = id number, title of the page is the matches name, extra info is the info that stands with that id.
I don't know how else to explain this so I hope this was good enough.
Thanks for your time and reading this :)
You can use requests to select the page (the best way is to use $_GET as suggested by gbestard) to select the ID. Then you can have some static content (like url or short article or link to screen shot or something similar) stored in your database under the same ID as the game, and upon clicking on the link to the game, the page is reloaded and you populate it with the new content, that was stored in the database.
You can even store entire pages with static html (as in article or short game description in your case) content and etc in your database and simply call them to populate a div.
If you have something like a custom made admin section of your site, you can add a page to edits it with a js plugin like ckeditor and the creation/editing of articles will be a piece of cake.
It's pretty much a standard case of a CMS(Content management system).

Display column-based instead of Row-Based records in PHPMaker 10

I'm having trouble and I wanna ask, if it's possible to have column-based tables when PHPMaker generates tables for records? Because when I generate it only generates row-based records. Copy-paste the link below to URL to understand. I'm sorry I'm not knowledgeable in PHP that much. It's just very easy to make a complete application with this program and the only thing stopping me is the format of how it's shown. An example of how I wanted it to look like would be this one
I hope somebody answers! Thanking you all in advance!
That kind of column based view is not suggested as it has many flaws when we try to display huge number of records. Adding pagination or sorting feature is very difficult and not user friendly.
As you have so many fields you could try to group them into tabs by relevancy. Once you put them under different tabs they can be easily navigated and easily fit into row based structure.
Creating tabs is PHPMaker is very easy, on field configurations screen you will get Page No config next to each field. By default it set to 1 you can set required page number as per your choice. Once you done go to Table config of the table which is second tab available for each table. Scroll down to bottom and and click on 3 dots next to Page Labels config (Under Multi Page Config). This will pop up a screen where you can add captions for your tab.

i need a simple javascript to add and multiply costs

can anyone give me a javascript that can do following.
I have predefined price for a product (lets say A). the consumer can select the quantity (lets say B)for that product. and the total price(lets say C where C=A*B) shows up on the same page without him actually pressing any button.
If there are 5 different products he chose then at the bottom the total price ("C") for each product adds up automatically (lets say D)at the bottom. (i will use this total price ("D") by passing it into a header command of php on some other page). I know html and css and a little php but i have no idea of javascript. I am making this website for a book store . The owner is a real good friend and i want to make it the best i can. Thanks for your help
for example
this is what i want to happen. i am selling 5 different books on the same page. you can select the books you want and the quantity of each book. ( for example 3 books of type 1 and 2 books of type 2). At the bottom of the page the calculation occurs automatically and the buyer can see the total amount he has to pay
I suggest looking at:
http://www.w3schools.com/jsref/event_onchange.asp
http://www.w3schools.com/js/js_obj_math.asp
And
http://www.w3schools.com/ajax/default.asp
The final one is more complex, and is for the dynamic post to the PHP file. Before asking for the code from someone else, try your hardest to see if you can learn to do it yourself... it'll count in the long run.
The only trick in JavaScript for adding or multiplying numbers is that, you should first get sure they are numerical values rather than strings. To do that, you can cast them to numbers via:
var value = $('#input').val();
if(Number(value))
{
// Do your work here
}

Effective pagination of decreasing results

I'm working for a client who asks me to prepare a module for its website (written using Yii) with the following features:
It shows 3 elements from a mysql_result, starting from offset=0.
The user can click on any of them to mark them as "read". That makes the desired item to disappear and to appear what would be the following item. That is, if you are showing items 3 4 5 and you click on 4, that item would disappear and appear the number 6, meaning the result would be 3 5 6.
The elements being shown are partial views and the button that "deletes" the item is a widget within each partial view.
The user can move through the list of items using some << and >> arrows to go back and forth the result.
One of the options the client gave to me was to show a list of pages ( 1 | 2 | 3 | 4... and so), but deleting items means the number of pages will decrease at some time in the future, plus if the amount is pretty big, I would need something more flexible such as only showing the current and other 4 pages at most. Another option is to keep the << and >> arrows.
I've tried to convince the client that pagination and a "live list" is a pretty bad idea, but he rejected the idea to limit the visualization to only the first 3 items (keeping in mind that eventually you will delete them and thus will be able to see the following items).
I'm developing it using Yii, MySQL and jQuery, and I'm not able to use CPagination because of this living list. I'm not asking the code, just some guidelines because I got lost the third time I tried doing it.
Some basics about the system:
I got a controller which loads the first 3 items of this module.
I got some actions in this controller that fetches the next item within a page (which may not be the same of the current object, though. One of my problems resides here), and the full page.
Each item is able to mark itself as "read", which will make the item not appearing the next time you fetch some results.
Every 1 second I check for items that have been marked as read, remove from DOM and append some new items using the action I defined in the second bullet.
Every time the user hits the << or >>, I reload the previous/next page (That would not be a problem apparently. If you're in the last page and there aren't more items to add, you just remain there. However if you empty the page, I don't have any method to detect that and scroll one page back).
As you may see, this headache would be easier without the pagination buttons, but the client obligues me to put them. What would you do guys? Thanks in advance
EDIT: The client decided to get the results in a random flavor. There is no more pagination, so the problem has disappeared. The #thaddeusmt answer may not have helped me really much, but I'll give it as valid, as it might be plenty useful for other people with similar problems than mine. Cheers
It seems to me like the CGridView or CListView should basically do this automatically. They support AJAX updating/paging out-of-the-box.
I assume that you have an AJAX action that like "actionMarkRead()" which you are calling when the user clicks. I assume that this sets some database field somewhere saying that the user has "Read" that item. To make this work with the CListView, just make sure that the CDataProvider has a condition which checks that "read" field (might have to JOIN a table, I don't know what your DB looks like). Then, when the list reloads via AJAX, it will have the correct # of pages to represent the smaller number of pages the CDataProvier query is returning.
I just tested this and it works!
The way I tested it is I set up a CGridView with 'ajaxUpdate'=>true,. Then in my CDataProvider I set 'pagination'=>1 to make it easy to test. Then I used the default AJAX actionDelete in my Controller to delete the items. Every time I deleted an item via that AJAX action link in the CGridView, the grid refreshed via AJAX and page count shrunk by 1. Seems to work like a charm!
Cheers and good luck!

Creative way to display tables with 35 columns

I have a form where users are entering 35 different fields.
I have a Content Management System where I want to display the results of an order on the form.
I've thought about adding a horizontal scrollbar inside the table, or limiting the table to the 10 most important columns and then making it so the administrator has to click on an entry to view all of the information on its own details page.
Do you know any creative ways that I can display the 35 fields on one page?
A standard Master/Detail Form should work. The table/grid would have key pieces of data and below it, the detail form would have all the details in a user friendly layout. To see the detail a user simply needs to select or click a row in the table/grid and the information rendered in the detail area is updated by the On_Click/On_Hover/etc event.
I don't know if this will fit your needs, but the jQuery ScrollTo plugin might be an interesting alternative to just a plain horizontal scrollbar.
Edit: There is another addon you might want to look at called columnManager.
I have had instances dealing with grids that are wide. In my own opinion, I think it is best to use the browser's (horizontal) scroll bar instead of having an "inner" (horizontal) scrollbar. A problem with http://demos.flesler.com/jquery/scrollTo/
Also, no clicks are involved or whatsoever. The user will be able to see everything by just scrolling. On the other hand, allowing the user to hide/show columns would also be good.

Categories