Next/Prev conetent with Ajax,PHP and Mysql - php

I hope to create a list of matches of a soccer champion of every week,so I want to get a result with next and prev button,so something like that:
Next | week 3 | Prev
-------------------------
tream 1 1-0 team 2
The list of teams I get it from another php page "content.php" and I used HTML "table" to make list
Finally I hope to get all content for every week from "content.php" and change it when I click next or previous buttons...

Ok,I found a great and simple solution here http://www.w3schools.com/php/php_ajax_database.asp
tnks.

Related

Dynamic PHP / MYSQLi Pagination

I'm trying to make pagination work on my site dynamically and I'm not sure how to change regular pagination to accomplish what I need to do and I was wondering if a PHP guru could help out!
Basically, once a week a report runs and populates records for the last week in my database. Also, at the end of the month, the report runs and pulls in the last month of data.
I would like to build my PHP page so that all items in the same month (~4-5 weeklies and 1 monthly) show up on the same page, and that each pagination page is a different month's data.
Currently the weeks are stored as two fields, start and end date, in the format: 2018-mm-dd.
How could I have it so that page 1 is all 2018-03 records, page 2 is all 2018-02 records and page 3 is all 2018-01 records? I also would like this to be automated so each newest month becomes thE new page 1.
Does this make sense? Is this possible? Any assistance would be greatly appreciated!! Thank you very much!!!

Add on numbers in a table

Say i have a database with a table which i have numbers on. Is there some way that i can add 1 number digit onto another one. for example i query what the fist number is and then add 1 number on to that. like if it was 1 and i clicked a button it will make it 2. How would this be possible? At the moment i just add a 1 into a new row every time but i need it to be classified under names. and it is really easy the way i have it now. if you don't understand don't hesitate to comment.
mine. it adds up all the ones
1
1
1
1
1
what i need to accomplish.
joe frank 1
and when i click the link
joe frank 2
Does that make sense

PHP pagination unordered list item

I'm getting an array value from external source and I'm converting it to into unordered list to display on webpage. But sometime contents of the list are very large to display on the single page. Is it possible to paginate the content so that it can show 10 list item per page.
<div id="a">
<div id="object3">TRIVIA</div>
<div class="details">
<?php foreach ($tri as $key): echo "<ul><li>$key</li></ul>"; endforeach ?>
</div>
</div>
Yes, but it requires actually writing a paginator.
You will need, however, to be able to get a count, and be able to display a range of results based on a url string like ?start=10&end=20.
The rest is simply using either a for loop or a foreach with a (if(count<start)continue;) and (if(count>end)break;)
You also need to generate links to go forward and back at the very least, and to not generate a link if you are at the start or end of the total count.
The only piece of information you need to pass in to your script is the page number, since that is the only thing that changes between pages.
There are other bits of information you need to know, such as numberPerPage, but they are included in your script and never change.
Here is a MySQL statement that will get you started:
SELECT columnList
FROM table
ORDER BY someColumn
LIMIT 10,5
The LIMIT clause says skip the first 10 records, then give me the next 5. This is the foundation and starting point for all pagination scripts that utilize a MySQL backend.
So how do you know the offset?
By that external piece of information I mentioned earlier, the current page number, combined with the internal piece of information I also mentioned earlier, the number per page.
If you are wanting to view page 5 and you intend to show 10 elements per page, then it is pretty easy to see that you want to start at row #41:
Page 1 showed elements 1-10
Page 2 showed elements 11-20
Page 3 showed elements 21-30
Page 4 showed elements 31-40
Page 5 needs to show elements 41-50
You can calculate the offset then this way:
$offset = $numPerPage * ($curPage - 1)
On Page 1, the offset will be 0 (which is what you want).
On Page 2, the offset will be 10, and so on.
Here is a link to a more thorough tutorial on pagination.
PEAR's Pager package has been made for this task. See the examples.

MySQL traverse graph data and get non-cyclic path

This one is a hard one for me to solve, basically I have data in a table looking like this:
id a b
1 2 4
2 4 2
3 5 2
4 2 5
5 6 2
6 2 6
7 8 6
8 6 8
9 5 6
...
You can see how complex the structure gets if you try to establish what parent has what children:
[2->[4->[2->RECURSIVE], 5->[2->RECURSIVE], 6->[2->RECURSIVE, 8->[6->[8->RECURSIVE]]]], ...]
I fear MySQL alone can't manage to efficiently find a path, but considering I write this in PHP maybe I could write some way for it to maybe first query the 800 lines of code then program an efficient way to parse the data.
The idea is that this function that I am trying to make, let's call it makePath() takes two parameters and returns an array with sub-arrays and the id's referring to a line in the data table.
For example makePath(2,8) would return:
array(array(2,6,8), array(2,5,6,8))
Since these are the only paths going from 2 to 8 without backtracking (i.e. going [2,5,2,6,8] and infinite other combinations of paths.)
I am stuck on how to start all this, hopefully someone brighter than me on the graph and cyclic theory could explain how I should start my code -thanks for your time!
You should be able to do this with a depth-first search on a directed graph structure. A basic outline would look like:
Create the graph. You'll need at a minimum a list of children and a visiting flag per node.
Call visit with the initial node. For your visit function, you'll need to know the destination node, have a reference to the result array, and keep track of the nodes visited along the current path in a stack.
If the current node is the final node, then add the path traveled (by going through the stack) to the result array.
If the node is being visited, then return.
If the node is not being visited, then
mark the node as being visited
call visit(recursion) with each child
unmark the node as being visited
If you need help with any of the steps, then please ask.

achievement system for consecutive actions

I'm about to create a new competition site, where users can upload pictures/vote.
I want to add some achievement bonuses/badges based on some very easy "achievements".
Achievement examples:
Login for 5 consecutive days --
Login for 10 consecutive days --
Login for 20 consecutive days
Vote 5 pictures (not yours) --
Vote 5 pictures for 5 consecutive days
I want to be able to add more achievements without adding too much code later on. A basic rule engine will be created.
Now.. I am having some troubles trying to think out how to do it. Anyone did something similar and wants to share database structure/coding examples, or someone with a good idea for this?
Read about 50 different threads on the topic here on SO, but couldn't find anything usable.
Make a new field in the table that will contain the date of the last activity (probably name it like lastactivity), and then create another one and name it something like consecutive. After that, each time the user login (or vote), check the last activity date and if it's yesterday, increment the value of the field consecutive by one and update the lastactivity field. Otherwise, reset it to 1.

Categories