Dinamic pages, based on MySQL Query, show 10 rows per page

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Martini002

Member
Feb 17, 2017
36
0
0
40
Hello guys,

I have many IP records concerning to my user stored in a MySQL Table,
so I must do a Query like this:

Code:
SELECT IP FROM ipTables WHERE UserName = 'Martini002'

I do not know how many records there are, how can I display 10 records per page?

Idea 1:
- Store the query result in a array
- In case of the second argument used in the command:
/iphistory Martini002 2
then set pos1 = (arg-2 * 10) and pos2 = (arg-2 * 10 + 10)
- Show items from pos1 to pos2 of that array

Idea 2:
- Count the max rows for Martini002:
Code:
SELECT COUNT('IP') FROM ipTables WHERE UserName = 'Martini002'
Store that result and set maxPages = result/10 (Rounding it to the next number)
- In case of the second argument used in the command:
/iphistory Martini002 2
then do this query:
Code:
SELECT IP FROM ipTables WHERE UserName = 'Martini002' Limit 10 OFFSET '%arg-2*10%'

---

The problem here is:
- I am newbie using Skript, I just made one SK and works very nice with MySQL but not sure if the method that I am using is the most efficient for doing queries.
- I do not know how to use arrays, one guy was explaining me about sections, but I did not understood very well how to use them.
- I do not know how to round numbers, sorry but the documentation is not very organizated at least I can not find some things.
- I do not know how to store more than one record from queries, I did not find out yet how to perform this.
- Actually I am doing individual queries...

Sorry if I mix various things in this thread but, I need your help..

---

Look at this example when performing a query:

Code:
        #Query how many refers have this player
        set {_result} to mysql result of query "SELECT COUNT(`Referente`) From lncbunonlinetime.referidos WHERE `Referente` = '%arg-2%'" 
        set {_refPlayer::*} to mysql string "COUNT(`Referente`)" in {_result} 
        
        set {totalRef-%arg-2%} to {_refPlayer::1}
        
        #Who was the last refered       
        set {_result} to mysql result of query "SELECT `Nombre`  From lncbunonlinetime.referidos WHERE `Referente` = '%arg-2%' ORDER BY `FechaRegistro` DESC LIMIT 1" 
        set {_refPlayer::*} to mysql string "Nombre" in {_result} 
        
        set {ultRef-%arg-2%} to {_refPlayer::1}      

        #Date of the latest refer
        
        set {_result} to mysql result of query "SELECT `FechaRegistro`  From lncbunonlinetime.referidos WHERE `Referente` = '%arg-2%' ORDER BY `FechaRegistro` DESC LIMIT 1" 
        set {_refPlayer::*} to mysql string "FechaRegistro" in {_result} 
                              
        set {ultRefFecha-%arg-2%} to {_refPlayer::1}
        
        set {_refPlayer::*} to "Nadie lo ha referido aun.."

        #Who refer him
        
        set {_result} to mysql result of query "SELECT `Referente` FROM `referidos` WHERE `Nombre` = '%arg-2%' " 
        set {_refPlayer::*} to mysql string "Referente" in {_result} 
                              
        set {referente-%arg-2%} to {_refPlayer::1}

I hate this example, it must be done with less code.. But I do not know yet how to work with arrays

---

I am using Skellett addon for MySQL.

Hope you can guide me

Thanks
[doublepost=1487544268,1487472796][/doublepost]@LimeGlass can you help me here please?
[doublepost=1487652900][/doublepost]BUMP
 
With SkQuery, you can easily get the first value of your column like this :
code_language.skript:
set {_value} to the first element out of objects in column "ip" from result of query "SELECT `ip` FROM `player_ip` WHERE `uuid` = ""%uuid of player%"""
But I don't know how to get a list from multiple rows :/

Personnally, I would like to get easily a value like with skQuery, but with Skellett...
 
Status
Not open for further replies.