Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-28-2011, 10:38 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #2  
Old 12-28-2011, 10:56 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #3  
Old 12-28-2011, 10:59 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #4  
Old 12-28-2011, 12:19 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Gunderak View Post
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.
__________________
Reply With Quote
  #5  
Old 12-28-2011, 12:54 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Gunderak View Post
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.

Last edited by ffcmike; 12-28-2011 at 01:05 PM..
Reply With Quote
  #6  
Old 12-28-2011, 06:52 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #7  
Old 12-28-2011, 06:57 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by Gunderak View Post
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.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #8  
Old 12-28-2011, 07:04 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Thanks, Looking into it now.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #9  
Old 12-30-2011, 03:28 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
You might also want to escape any user entered text. So as to not allow for SQL Injections.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:46 PM.


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