SA-MP Forums Archive
Read from Mysql? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Read from Mysql? (/showthread.php?tid=624886)



Read from Mysql? - daghost111 - 24.12.2016

Hello,today i was trying to create a command /banlist for my server,that will get all the names from the table "bans" and row "name" and will show me banned players.I dont know much on mysql and i need your help....

I will show you the line i use to store bans on database,maybe that will make it easier :

Код:
format(q, sizeof(q), "INSERT INTO bans (id, name, reason, ban_time, issue_time, expiry_time, admin, ip) VALUES ('', '%s', '%s', %d, %d, %d, '%s', '%s')", namegive, reason, time, curtime, expire, name, ip);
	mysql_query(q, THREAD_INSERT_BAN);
Thank you!


Re: Read from Mysql? - daghost111 - 24.12.2016

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
Giving you a query right now will not teach you anything.
****** and read! http://www.w3schools.com/sql/
Still can not get it to work....!I know it needs to be done something like:
Код:
format(str,sizeof(str),"SELECT 'Name' FROM bans .......;
But it does not work!
Anyone can help,because i need it right know.I dont have time to learn all mysql


Re: Read from Mysql? - Konstantinos - 24.12.2016

Without apostrophes around the name of the column because that makes it as a literal text and will retrieve "Name" instead of the data you want to.


Re: Read from Mysql? - daghost111 - 24.12.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Without apostrophes around the name of the column because that makes it as a literal text and will retrieve "Name" instead of the data you want to.
Yeah,but i dont know how to store it to the mysql result and then use it as a string so it will show me all names...


Re: Read from Mysql? - BiosMarcel - 24.12.2016

https://sampwiki.blast.hk/wiki/MySQL/R40#mysql_format

you can create queries with that, it is like string format


Re: Read from Mysql? - Konstantinos - 24.12.2016

1) Loop from 0 to rows-1
2) cache_get_value (R40+) or cache_get_row/cache_get_field_content (R33 to R39-6) function inside the loop to retrieve the data, where rowid = iteration variable
3) re-format or format + strcat to "join" the text with the rest


Re: Read from Mysql? - daghost111 - 24.12.2016

I can not get it to work.Im really bad on this mysql sh*t.Thanks anyway....