In JQGrid I want to show group data on one page. That is, if containing all of the items in an order would exceed the list limit, then no items from that order are contained and the list is simply slightly shorter than the limit and shows data to previous order. Is there any way?
Personally I think that this should be done at server and not at client grid. If I understand right , suppose you have 10 items limit per page and the response contain 8 from one group and 2 from the other - if the second group contain really 2 items, which will be deleted, this will be not correct.
In case there are more records from previous page - the previous deleted 2 records should be included into the next page, but according to your server response they will be missed.
Related
I have a webgallery (made with laravel) and would like to add the possibility to reorder the images... Now, I have thought of several approaches but for every aproach i find that there should be a better way of doing it.
the gallery does not use javascript, so ones changes have been made it needs to be sumbitted and reloaded to reflect the changes
The main difficulties are:
how to store the order in the database? an additional Integer column?
how to add a picture "between" two others?
how to handle it at a frontend level?
So far the best ideas I had are these:
a column with integers, order by clause on this column. Frontend: a move up and a move down button.
problems of this solution: it needs a refresh after each single movement. it needs to identify the previous/next picture and swap the number with that one. To move a single pic from the end of the gallery to the top it takes forever.
a column with integers, automatically prefilled in steps of 100, order by this column + upload time in case of same numbers, Frontend: a textbox where the user can specify the integers for each picture and a submit button.
problems of this solution: does not look very professional. solves all the problems of the previous solution
same as previous solution but with double values to be able to insert pictures without limits.
They all dont seem the real deal.. Any sugestion on how to do it properly is welcome. thanks
I have done that kind of sorting in OpenCart products list (custom backend design)
Sort order was additional column order INT(11) in database
We had 3 input fields: up/down/custom
Where custom was dropdown of all indexes from 1 to max-items.
All inputs does the same:
Take new order value and shift all elements except itself. Up or down shift depends if you move element to front or to back of current position
UPDATE order FROM products SET order = :newOrder WHERE id = :currentItemId
if ($newOrder > $oldOrder)
UPDATE order FROM products SET order + 1 WHERE order >= :newOrder AND id != :currentItemId
else
UPDATE order FROM products SET order - 1 WHERE order <= :newOrder AND id != :currentItemId
Inserting does the same update, just first query becomes INSERT INTO
To get rid of ugly refresh of page on every action we do Ajax requests and re-sorted DOM with jQuery
I am using sphinxsearch + php for full text search in my app.
I need next prev buttons on my product page. For example I run query "Men shoes" it returns me result of 20 shoes (paging limit is 20), then I click into product and open up a product page, and here I have next and previous products. But next and prev should work to specific to my search query "Men shoes". I store my query in session, and I have ID of product. So how can I find the position of these product and increment or decrement it find products I need.
Is it possible to without query-ing the whole table and looping through to find what I need.
While you can* create a cursor solution, it may be simpler to just use offset.
Page 1 is offset zero, page 2 is offset 20, page 3 is 40 and so on.
where you call setLimits, you can set the offset.
*Basically you need a consistent sort order, and need to store the value of the column, as the 'cursor' for paging, and use it for filtering the next page. If sorting by weight, you store the weight of the last result on the page. Then for the next page, you only want weights bedlow that one. (with weights is even more complicated as there can be many results with the same weight, so you need to do multi-column sorting)
For eg I have 5 records of same user. What is the best way I can sort and display each one of them on a different page using next and previous links.For eg on clicking previous i must get previous record. Then i again click previous i must get previous to that record and so on.
Pick an order and set it with ORDER BY [order], then use LIMIT start, amount to slice the result.
I am trying to build a website with mysql and php. This is the first site I have attempted so I want to write a little plan and get some feedback.
The site allows users to add some text in a text field as a “comment”. Once the comment has been entered into the site it is added to the database where it can be voted for by other users.
When a new comment has been added to the database it needs to create a new page, e.g. www.xxxxx.com/commentname or www.xxxxxx.com/?id=99981.
There will be a list of "Comments" in the database along with the number of votes for each comment.
The home page will have two functions.
1) Allow users to add a "comment"
2) Display two tables, each with 20 rows containing most "popular comments" and "recent comments"
Each comment will generate its one page where the comment will be displayed. Here users can read the comment and Vote for the comment if they wish.
Please help me out by explaining how to do the following.
-Generate a new page whenever a comment is added to the database
-Add a vote to the vote count in the comment database.
-Display the top 20 most popular comments as per number of votes.
-Generate a new page whenever a comment is added to the database
You only need a comment.php file with a MySQL query getting the given comment out of the database. I would recommend to use the comments primary key to get the comment. Using rewrites you can have a URL like this: www.xxxx.com/comment/1. If you need the redirect for a specific link structure ask again.
-Add a vote to the vote count in the comment database.
Just add a column to your table holding the votes. If you have logged in users and you want then to check their votes, create a new table for the votes and another table for the many to many realtion.
-Display the top 20 most popular comments as per number of votes.
This is simply done by sorting in the MySQL queries and selecting only 20 results:
// For the recent 20 comments
SELECT * FROM comments ORDER BY id DESC LIMIT 0,20
// For the 20 most popular comments
SELECT * FROM comments ORDER BY votes DESC LIMIT 0,20
Any further questions?
This is a pretty broad question, i don't think we'll be able to help you fully here at stack without making a full blown php blog tutorial!
I'll try and point you in the right direction however. Firstly i'd say take a look at wordpress, even though i presume you want to make your own custom one, wordpress would be a good starting point for code inspiration? (Just a thought)
The way i'd generate a new page, would be to make a php page, say comments.php, which using the $_GET variable, gets the related record in the database and displays it.
Adding a vote up or down is as simple as adding form to the page with two submit buttons, one with a value of 1 one with a value of -1, upon submit it sends its value to the database, and takes the existing vote value say 25 and adds its value so, if u up voted 25 + 1 = 26 if you downvoted 25 + -1 = 24.
Displaying the 20 most popular comments is just a case of using some SQL sorting, something like this would work
SELECT * FROM comments ORDER BY votes DESC LIMIT 0, 20
That statement selects all the columns from the comments table, sorts it by the votes column decending, so highest value first, and then limits the number of records it fetches by 20, from there its a case of looping through each record and displaying it how you wish.
I hope this atleast gets you started on the right path :)
I have a friend who runs an online auction website. He currently has a featured items section on the homepage that he wants to have cycle an item every X amount of minute. The site runs off a MySQL database which I haven't actually seen yet.
The current code that he is using is a big, long messy Javascript code that is causing all kinds of errors.
The items would have to cycle in order and when they get to the end, go back and repeat again.
What would be the best approach to take to this using PHP?
EDIT: I mean from a backend SQL perspective. Not the UI.
Thanks
Ben
Assuming you have a separate table for the featured items (probably has an item ID referencing the main items table and maybe other info)... In this table, add a last_featured column to represent the time the item was last shown. From there, you can manipulate your queries to get a rotating list of featured items.
It might look something like this (as a weird pseudocode mix between PHP & MYSQL):
// select the most recent item in the list, considered the current item
$item = SELECT * FROM featured_items ORDER BY last_featured DESC LIMIT 1;
if ($item['last_featured'] > X_minutes_ago) {
// select the oldest item in the list, based on when it was last featured
$item = SELECT * FROM featured_items ORDER BY last_featured ASC LIMIT 1;
// update the selected item so it shows as the current item next request
UPDATE featured_items SET last_featured=NOW() WHERE item_id = $item['item_id'];
}
Note that this requires 3 call to the database... There may be a more efficient way to accomplish this.