Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   List all items in a SQL table? (https://forums.graalonline.com/forums/showthread.php?t=134265433)

Gunderak 12-28-2011 10:38 AM

List all items in a SQL table?
 
I have been working on a support system where users can enter in a question for staff to answer about the server, my question is, how can I list all the rows in a table?
Would it be possible using a scroll as a container and a text list?
something maybe even to get all rows SELECT * FROM Support then a for loop with like
PHP Code:

with(Text_List){
  for(
temp.indx 0temp.indx this.data.size(); temp.indx ++){
    
addrow(indxdata[indx]);
  }


Maybe a better question is how would I add it all to an array?

cbk1994 12-28-2011 10:56 AM

It sounds like you don't have a good understanding of SQL concepts. You should try reading some tutorials for SQLite or even MySQL online. Unlike what you've been doing thus far, SQL is very easy to do terribly and horribly wrong if you're just copying and pasting from examples you've found/are given.

PHP Code:

temp.req requestSQL("SELECT * FROM table"true);
temp.rows temp.req.rows;

for (
temp.row temp.rows) {
  
// you can access data via temp.row[0], temp.row[1], etc...
  // or with the column name like temp.row.submitter, temp.row.title, ...
  // 
  // the latter is preferred
  
echo("Row: " temp.row);


Obviously you can only do this serverside so you will have to send it to the client just like you'd send any other data.

Gunderak 12-28-2011 10:59 AM

I have read some things and understand how to use SQLite, it's rather easy.
W3 schools had a good example which I learnt most of it from.
But I was just unsure on how to get all the rows.
And I take it with you're example you'd send it to the client then do a for loop and then just get like temp.rows.size and add rows into a text list?
Thanks!

And the only really thing I think I'm doing wrong is where it has like var char null by default and crap like that.

cbk1994 12-28-2011 12:19 PM

Quote:

Originally Posted by Gunderak (Post 1679705)
I have read some things and understand how to use SQLite, it's rather easy.
W3 schools had a good example which I learnt most of it from.
But I was just unsure on how to get all the rows.
And I take it with you're example you'd send it to the client then do a for loop and then just get like temp.rows.size and add rows into a text list?
Thanks!

It's just an array of rows, you would probably want to display each row with GuiTextListCtrl.addRow by looping through them.

Quote:

And the only really thing I think I'm doing wrong is where it has like var char null by default and crap like that.
SQLite doesn't use VARCHAR, you should just use TEXT.

ffcmike 12-28-2011 12:54 PM

Quote:

Originally Posted by Gunderak (Post 1679703)
PHP Code:

with(Text_List){
  for(
temp.indx 0temp.indx this.data.size(); temp.indx ++){
    
addrow(indxdata[indx]);
  }



It's a bad practise looping through an array which can not change its value mid loop while using .size(), especially if it's a large array such as can be expected from an SQLite table, this can create a lot of overhead.

Gunderak 12-28-2011 06:52 PM

On a related note, I have made a system now, but I want to replace a value.
insert into etc isn't replacing it at all and I don't know how delete works or drop.
Can anyone possible help?

Tolnaftate2004 12-28-2011 06:57 PM

Quote:

Originally Posted by Gunderak (Post 1679740)
On a related note, I have made a system now, but I want to replace a value.
insert into etc isn't replacing it at all and I don't know how delete works or drop.
Can anyone possible help?

You're gonna want to use UPDATE.

Gunderak 12-28-2011 07:04 PM

Thanks, Looking into it now.

scriptless 12-30-2011 03:28 AM

You might also want to escape any user entered text. So as to not allow for SQL Injections.


All times are GMT +2. The time now is 07:31 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.