I have an archive page that displays the number of articles published. Because there were so many, I ran a pagination script:
for 127.0.0.1/archive/2/?p=x&pp=y
where p is the page number and pp is number of articles to display per page
The pagination looks like this
Prev 1 2 3 4 ... 12 NEXT
with each item linking to p x
I also have the items per page setter: 25 | 50 | 100 (y)
Now I have a PHP script that fixes pp into a session variable. But I am worried about duplicate content (since incrementing pp values will be inclusive) and also content not getting indexed because its not in the pagination link. so in the example above, pages 5-11 will not be indexed.
Any ideas on how to fix this?
Related
I am playing around with PHP and SQl. Currently I am building a test page that contains the earth's fauna. Right now I will only focus on trees and flowers. When someone first visits the page, they will see a list like this.
Trees
Pine Likes 10 Comments 11
Oak Likes 20 Comments 2
Cedar Likes 7 Comments 1
Flowers
Rose Likes 209 Comments 4
Orchid Likes 550 Comments 193
In order for me to count the likes I go through every single tree and flower type then do a count for each of their comments and likes. Since this is fairly new, this doesn't take a long time. What scares me is that what would happen if this becomes bigger. I am aware that SELECT COUNT(id) is fast, but when you do it on multiple records it can slow down a page.
Now, my question, is: Should I instead create another table called totals, and store the total comments and likes of an item. With the new table when someone creates a comment or like, or unlikes and deletes comment, I could add or subtract from the totals.
I have a mySQL table which stores categories and subcategories nested to unlimited level. The table structure is :
cat_id, parent_id, cat_name
1 0 Ingredients
2 1 Veg
3 1 Non-veg
4 3 Egg
5 2 Potatoes
I want to show the complete list of these items in a PHP page in a tree view. So first the items that have parent id "0" will be shown and if they have child items the child elements will be shown with recursion to unlimited level. The output will be something like the following but in table format :
id title
1 Ingredients
2 Veg
5 Potatoes
3 Non-veg
4 Egg
I am able to achieve this with the help of multiple queries. First I get all the records with parent id = 0 and then I loop through all the items and inside the loop I check if there are child records present show them (recursively).
But now I need to add pagination and show only 10 records per page.
Is there a way to achieve pagination and dynamically show 10 records per page including the child and child-child records ?
How will I calculate the total number of pages and get the records ? I will also have to add filters later in these type of tables.
You mean, only 10 records of the root items, the ones that have cat_id of 0? For your first query, just do SELECT * FROM cats WHERE parent_id = 0 LIMIT 10. Then your subsequent queries will only find the descendants of that first 10.
For total number of pages (sets of 10), do SELECT COUNT(*) / 10 AS number_of_pages FROM cats WHERE parent_id = 0.
there is a fast way to get all results in an html table, and then apply jquery pagination like :
$(document).ready(function() {
$('#mytable').DataTable();
} );
site source : https://www.datatables.net/examples/basic_init/zero_configuration.html
by this the client will wait only the first time, and after this, click next is directly a client event not necessary to disturb the server.
also you php and html will be clean with a lot of functions like :
sorting, filters, search, ...
demo in jsfiddle : http://jsfiddle.net/0wvtpzc8/
I am making a wordpress template. I have a news category.
I want to display the first 4 posts in 1 column, and the next 4 in the second column and all the remainder in column3. I know how to create the columns and so forth.
My questions is how do i actually get at the first 4, and the second 4 and then the remaining posts after I have started the query.
query_posts('cat=145');
Thanks
you can use offset in query_post, as query_post uses WP_Query in the backend
// First four posts
query_posts('cat=145&posts_per_page=4');
// Second four posts
query_posts('cat=145&posts_per_page=4&offset=4');
Hope it helps.
I'm building a webpage where the items listed in the webpage are dynamic, (The items are loaded from the database.) Say we have 19 items in the database. The maximum items allowed for a page is 4. Now I have 15 items remaining. I need the rest of the items in another 4 pages.
Like this --> Pg1 -> 4 items displayed
Pg2 -> 4 items displayed
Pg3 -> 4 items displayed
Pg4 -> 3 items displayed
As shown above my php code needs to identify the number of items and the number of pages required. What is the best way you would suggest me to do this.
Get the count of items in the database.
select count(whatever_id) as numberofwhatevers from mytable;
save it (in a variable or a class or however you feel comfortable)
$recordcount = $results["numberofwhatevers"];
$recordsperpage = 4;
$numberofpages = ceil($recordcount / $recordsperpage);
The only complicated bit is querying a subset of the records to match whatever page you're on... for example, if you're on page 3, you want records 9-12.
select * from mytable limit 9,4;
I know the title may not be exactly what this is about but bear with me.
I don't know how another title for this.
Well look this is my situation.
I'm building a little cms system (for myself and to learn from it). I want the pages inside the CMS to be listed and ordered by categories.
It will look something like this:
Webpages
- Home
-- homepage(this is the web page itself)
- News
-- Latest news
-- Archive
this system would mean I will have sub-categories.
In the database I have made a table:
| ID | Parent_ID | Name | Lable | Order|
1 1 Webpages webpages 1
2 1 Home home 1
3 1 News news 2
As you can see here the main category is the Webpages category and Home and News are sub-categories of it.
And those 2 categories are ordered so the Home category is first then the News second.
The problem I'm facing is this:
If i want to get all the sub-categories means i need to start with the main category Webpages and with that ID i can get the sub-categories of the main category.
I think you can see how deep this can go en that would mean (I think) that there will eventually be many query's that will be run for each sub-category.
So my question is:
Is there a way to get all the sub-categories at once in the correct order in one ore 2 query's.
if you have an answer, please let me know.
thnks
When writing the query you will need to use the ORDER BY clause. For this specific example you will need to ORDER BY Parent_ID, Order. This will return sorted by Parent_ID and then sub sorted by Order.
You can then use mysql_fetch_assoc() for parse the result set into an associative array.
Since you are going to have multiple levels of hierarchy you will have to loop through the result set once store it in a associative array consisting of the hierarchy structure.
This array can then be used to display the appropriate navigation hierarchy on the page.