I have been asked if I could number products in the admin area of OpenCart 1.5.
The numbering would be like:
1
2
3
4
5
etc and continues on the next page.
I am just unsure how to do the count and pull the numbers through into the view.
I've never used OpenCart 1.5 before, however, with a little PHP you could make it work:
Your result array is probably indexed. Add 1 to the index and you have your row number.
For pagination support you just need to use the following equation: (index + (page_size * (page_number - 1)). Then, you'd just add one for each item.
Depending on how your product table is set up, you might also be able to output the primary key of the table. Quite often, those will start at one and increment by one each time. The problem with this, however is that if you delete product #3 then you'll have a gap in your numbers.
Good luck!
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)
I am using Excel 2010 and have a list of products (~8000) that I need to create product code / part numbers for. These product numbers need to be based on 4 levels of categories, where each category has a code (2-3 digits of numerical values). For example:
Model01: 15
Primary Category01: 11
Secondary Category01: 45
Tertiary Category01: 22
Primary Category02: 22
Secondary Category02: 50
Tertiary Category02: 23
So for example says Product A has the categories of Model01 > Primary Category01 > Secondary Category01 > Tertiary Category01 it would have a product code of 15-114522. I have this where it works in Excel. HOWEVER, at the end of each "Category Code" I also want to have a unique number to differentiate products in the same category combination. So I would want Product A to have a product code of 15-114522-XX (XX being a unique identifier number that auto increments only for that combination of categories). So 15-114522-XX and 15-123456-XX could both use 15 in the place of XX.
So far I have tried finding the duplicates using COUNTIF and then ranking them sequentially so that each category code that was duplicated was ranked with a unique number, but that ranked all duplicates (different category combinations that were both duplicated. I found the formula to rank sequentially here: http://support.microsoft.com/kb/152567/en-us
So I need a way to generate existing part numbers and a way to continually generate new part numbers if we add products.
I really feel like Excel is not the best way to do this, so if you have another suggestion for a way to do it I would be glad to hear it. I know some PHP, so if I could use PHP and MySQL Database that would be fine. I feel like this might need to use VBA to accomplish this through Excel(which I do not know, but I am sure I can figure out).
I realize that this is an extremely hard thing to understand so I will also link a Google Doc of the Spreadsheet where you can view it or download it if you would like.
Google Spreadsheet: https://docs.google.com/spreadsheet/ccc?key=0AlXmrYIdv91SdEFQVklURkdTZER0NFkxZ1B4ZFdZYXc
I would appreciate any and all responses. Let me know if you need anymore information and I will do my best. Thank you!
-Jacob
Personally I'd place another column right of "Part Number" labeled "Part ID". Place the following into the cell and drag it down to copy the code with the relative cell references.
=H2 & COUNTIF($H$2:H2,H2)
So I got a problem that I can't wrap my mind around.
I'm creating a shopping list that is divided into ten categories of various lengths. (All of the items come from a database). I got it to work when using a single column, but I have to divide the list into four columns. The code should decide which categories should go where so that the four columns have the most equal number of items possible.
This is what the list will look like when the code is working.
Out of these ten categories, four of them have a specific category they belong to.
The way I've approached this is to count the total number of items and divide it by four to compute the average number of items per column. I put the four special categories in their respective column and kept track of how many items were now in each column.
Now I still have six columns remaining of various sizes. What is the best approach to put them in the column that would fit best? Since some categories are much larger than others, some columns could potentially have three or four categories.
UPDATE: Right after I posted this I came to the realization that I should find the column with the least items and add the largest category to it. This seems like it will work. And it looks like Dave is suggesting the same!
After writing your 4 "main" categories to the columns, make an array that has a total of each column:
$columnTotals = array(10,6,12,13)
//example - obviously you'd use count or something to get the totals
Then, order your non-special categories in an array by largest to smallest:
$subcatTotals = array(18,15,13,12,8,4);
//here, you'll have to get the totals, then use an array sort to order them
//probably want an associative array so you know which total matches which cat.
Then, in a loop, add the first(largest) sub-category to the smallest column, and get a new total for that column.
This SHOULD give you the most even columns you can get - at least it has in all the made-up examples I've tried it with.
Your approach is most ideal in today's context. Let me explain...
The ideal thing to do right now is do your little calculation and split the list into the number of rows & columns.
The alternative is a CSS3 approach. i.e., you can create the whole list in ONE column through PHP. And on the CSS side, you can specify the new property "column-count".
But there are issues. This is not yet properly standardised. So you've got to specify the -moze- prefix and -webkit- prefix depending on your browser. But the reason I wouldn't go for this is that IE still does not support this. And it's too early to consider an upgrade by all users even if they did.
Going one step further, you ought to modify your splitting algorithm to take into account the category headings.
Hope this helps :)
I'm currently working on a site that will display a list of online shops,
Each shop will be stored on my database and I'll be using PHP to select and display them.
But since those shops will pay me, I want to let each shop to be on the top of the list sometimes,
(for example if the shop name starts with a "Z", they will probably complain for being on the bottom of the list all the time, so I want to keep it fair).
So I thought about letting each letter be on the top of the list for an hour, but i have no idea how to do that..
Is that even possible?
Thanks in advance!
I'd show a separate box and call it "today's pick" or something with just one shop in it. That way you can push the shops starting with "Z" to the top once in a while and at the same time keep the user experience of a list of shops which is sorted normally.
Then use the database to save which shop has been in the "today's pick"-box how many times to get them all up there equally.
There's no sane way (that I'm aware of) to handle this directly in SQL without adding a "priority" field to your schema (although it's possible, it would be convoluted at best). That said, here are two suggestions:
Modify your schema
Simply add a "priority" field to the relevant schema and sort by priority, name (or whatever the default is). You will of course need to reset the priority field every hour, but this is a fairly trivial task.
Handle it in PHP
Carry out the query as per usual.
Grab all the results into an array.
Re-prioritise as required based on the current hour. (You'll need to array_splice the item(s) you want to bump out of the array and then array_unshift them to the top.)
Output based on the array.
This will of course become more convoluted/less efficient if you need to handle pagination, but the basic idea is the same.
A nice solution would be to add another column to the database with the shop names, and call it something like "last_shown" then when you show this shop, update the column with a timestamp, and each select do something like:
"SELECT name,link FROM shops ORDER BY last_shown DESC"
then in php you could check
<?php
if($row['last_shown']+3600 > now()){
//run select but in ASC order
//update the new row's column to the current timestamp
}
?>
that way it will only update once an hour, but otherwise it will keep selecting the shop at the top of the list for the hour
sorry it's a bit of a mess i just typed this out quickly at work
You can add
1) a extra column as shown_times in schema
2) order by shown_times asc
3) & as a shop is shown you would +1
or
Another solution :
You can even use ORDER BY RAND()