SphereCommunity
simple mysql operations - urgent - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: General Help (/Forum-General-Help)
+--- Thread: simple mysql operations - urgent (/Thread-simple-mysql-operations-urgent)



simple mysql operations - urgent - ChaveS - 12-05-2012 01:00 PM

Can someone make me an example to:

a function which create and save a new "table", right
CODE | Column 1 | COLUMN 2 | COLUMN 3
1 | SOME UID | SOME TEXT | SOME NUMBER

And then a function which:
return to sphere de column 1(UID) of line 4, for examle

thanks


RE: simple mysql operations - urgent - Shaklaban - 12-05-2012 11:47 PM

you can use phpmyadmin for creating tables, its easy to use it. in tables always use index, create column with named id and make it auto increment and index. with that every added row will have id, its useful sometimes.

also if you planning to create large tables with uids index uid columns it will boost the performance

about the other question:

PHP Code:
[function database test]
db.query "SELECT * FROM table WHERE uid = '<uid>' ORDER BY id DESC LIMIT 1"

SELECT FROMthis part means select all columns (column 1column 2)
if 
you want to return single column use SELECT COLUMN1 FROM

WHERE uid 
'<uid>' get the row which has uid=self in uids row (put uids in seperate row)

ORDER BY id DESCorder the returning queries by iddescendinguseful if you are making top15 like systems.

LIMIT 1limit to the returning rowsalways use limits because if sphere return large queries server will freeze so if you want to get the players from database which has most kills use:

[
dialog d_top_15_test]
gump codes...
db.query "SELECT * FROM table WHERE columnuid = '<uid>' ORDER BY KILLS DESC LIMIT 15"
local.x=30
local
.y=30
for 0 14
    ref1
=<db.row.<dlocal._for>.columnuid>
    
dtext <local.x> <local.y1152 <ref1.name>
    
local.+= 20
endfor 



RE: simple mysql operations - urgent - ChaveS - 12-06-2012 03:04 AM

Exactly what i want, The most important is learn the myadmin commands, and some examples, then ill try my functions on sphere scripting!

It helped! thanks!

If someone has more example please let me know? specially examples creating the tables, for texts etc
On old forum had a lot of examples but on new one, none yet...