Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Getting a field as a variable...

Quote Reply
Getting a field as a variable...
Ok..this is probably easy for most people..but this is the first plugin I have attempted to write that grabs some data from the SQL database ;)

What I am trying to do is grab the URL for a link, where the ID is equal to $id.

# connect to MySQl, so we can get the URL...
my $db = new GT::SQL '';
my $table = $db->table ('Links');
my $sth = $db->select ( { ID => \"$id" } );

I've got as far as the code above, but now I'm stuck as to how to get the field 'URL' returned into a variable that I am use elsewhere....can someone help me here please? Unimpressed

I've worked my wayt through the documentation to get as far as this..but I'm lost now Tongue

Thanks

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Getting a field as a variable... In reply to
You can always use the $DB object in your plugins, i.e. you don't need to create a new GT::SQL object.

So you could do:
Code:
my $table = $DB->table ('Links');
my $url;
if (my $sth = $table->select( { ID => $id }, ['URL'] )) {
$url = $sth->fetchrow;
}
The hashref in the select statement is your condition, the arrayref lists the field you want to get.

in general, you can use the following statements, depending on what you put into select (not sure if the list is complete)

Code:
$sth->fetchrow;
$sth->fetchrow_array;
$sth->fetchrow_hashref;
$sth->fetchrow_arrayref;
$sth->fetchall_arrayref;
$sth->fetchall_hashref;
$sth->fetchall_list;

Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Jun 18, 2002, 6:40 AM
Quote Reply
Re: [yogi] Getting a field as a variable... In reply to
Thanks Yogi..worked great (slight typo on line 3 of first example..missing $)....

The problem I am having now is with;

Code:
# now connect to the URL..to see what we get...
my $sock = GT::Socket->open({
'host' => $url,
'port' => 80
});

$sock->write( "GET / HTTP/1.0\n\n" );

print "REQUEST RETURNED:\n\n", $sock->gulpread(-1);

For some reason $url is not being passed along. Should it be in ""'s?

EDIT: I tried it with '' and "", and nothing again..but none of them worked. I printed out the value of $url, and that has a value for it Unsure

The error I am getting is;

>>>Can't call method "write" on an undefined value at /home/ace-clipart.com/public_html/directory/cgi/safe_jump.cgi line 51.<<<

Thanks

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Jun 18, 2002, 6:42 AM
Quote Reply
Re: [Andy] Getting a field as a variable... In reply to
What typo? Angelic

Use GT::Dumper to print what is stored in $url.

Code:
use GT::Dumper;
print Dumper($url);
after the fetchrow statement.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Getting a field as a variable... In reply to
I know it holds the right value, as just below it I added;

print $IN->header();
print $url;

That printed out "http://www.ace-installer.com", as expected...Unsure

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Getting a field as a variable... In reply to
You have to strip out the http://

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Getting a field as a variable... In reply to
Ah..that worked great :) I've got it grabbing the site now...but I'm getting the whole site Unsure Is there any way to limit it to just the;;

Quote:
REQUEST RETURNED:

HTTP/1.1 200 OK
Date: Tue, 18 Jun 2002 20:02:17 GMT
Server: Apache/1.3.23 (Unix) PHP/4.1.2
X-Powered-By: PHP/4.1.2
Connection: close

bit?

Thanks for your help...Smile

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Getting a field as a variable... In reply to
Ok forget my question in the custom jobs forum ;)

Have you read the pod regarding gulpread and max_down bytes?

Last edited by:

Paul: Jun 18, 2002, 7:13 AM
Quote Reply
Re: [Paul] Getting a field as a variable... In reply to
Yup..and it all flew right over my head Tongue About the only bit I understood was how to grab the URL, and get itsw status from there. I could just use a split() to get the status..but its a lot more long winded than other methods I would imagine.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Getting a field as a variable... In reply to
Try adding in max_down bytes into the open() method - set it to 12 or 15 if you want.

max_down => 12

...then see what you get :)
Quote Reply
Re: [Paul] Getting a field as a variable... In reply to
Ah..thanks. I was literally just playing with max_down option, and was at 2048...working my way down Tongue

Thanks

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!