We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › displaying multiple lines of text from an array
Page Index Toggle Pages: 1
displaying multiple lines of text from an array (Read 446 times)
displaying multiple lines of text from an array
Feb 24th, 2009, 11:28am
 
hello all i'm still trying to understand how display lines of text from an array. basically im reading in data from a mysql database and then trying to display it on screen line by line but so far it all comes out on one line.

I eventually want to start playing with the text but need to work out how to get it to appear properly first

code as follows

(yes im a noob)

import de.bezier.mysql.*;
PFont f;

// created 2005-05-10 by fjenett
// updated 2005-11-16 by fjenett


MySQL msql;


void setup()
{
   size( 400, 400 );

   f = createFont("Arial",20,true);


   // this example assumes that you are running the
   // mysql server locally (on "localhost").
   //
   // replace --username--, --password-- with your mysql-account.
   //
   String user     = "*****";
   String pass     = "**********";

   // name of the database to use
   //
   String database = "******";

   // name of the table that will be created
   //
   String table    = "inbound";

   // connect to database of server "localhost"
   //
   msql = new MySQL( "*************", database, user, pass, this );
   
   if ( msql.connect() )
   {  
     
       msql.query( "SELECT * FROM " + table );
       
       while (msql.next())
       {
         
         String s = msql.getString("message");
           int n = msql.getInt("id");
           println(s + "   " + n);
           fill(0);
           textFont(f);
           textAlign(CENTER);
           text(s,10,100);
         
         
           
       }
       
       // need to find out how many rows there are in table?
       //
       msql.query( "SELECT COUNT(*) FROM " + table );
       msql.next();
       println( "number of rows: " + msql.getInt(1) );
       
       
   }
   else
   {
       // connection failed !
   }
}

void draw()
{
 
}
Re: displaying multiple lines of text from an arra
Reply #1 - Feb 24th, 2009, 12:31pm
 
Create an int variable, eg. linePos, initialized at 100.
Use it in the text call: text(s, 10, linePos);
Then increment it with the text height: linePos += 20;
Re: displaying multiple lines of text from an arra
Reply #2 - Feb 24th, 2009, 12:38pm
 
how would i put that together ?
Re: displaying multiple lines of text from an arra
Reply #3 - Feb 24th, 2009, 12:56pm
 
never mind got it working how would you display text vertically?
Re: displaying multiple lines of text from an arra
Reply #4 - Feb 24th, 2009, 1:28pm
 
Use rotate().
U
n
l
e
s
s
you mean that way?
Re: displaying multiple lines of text from an arra
Reply #5 - Feb 24th, 2009, 1:53pm
 
i do mean
t
h
i
s
w
a
y
Re: displaying multiple lines of text from an arra
Reply #6 - Feb 24th, 2009, 11:57pm
 
I think you need to take each character of each string and position it "by hand" (or rather, calculation).
Page Index Toggle Pages: 1