Gossamer Forum
Home : Products : Gossamer Links : Discussions :

SQL and General Problem with Output

Quote Reply
SQL and General Problem with Output
Hi, Ian back once again at the SQL table!

This time its for a sub in one of my plugins (no prizes for guessing which one).

Code:
$lt->select_options ('ORDER BY RC_Count DESC, RC_IN DESC, Hits DESC', "LIMIT $topx");
my $sth = $lt->select('Title', 'RC_Count', 'RC_IN', 'Hits'); ($title, $rc_count, $rc_in, $hits) = $sth->fetchall_list;


I am trying to get $rank, $title, $rc_count, $rc_in, $hits for each row returned in the decending order and use them as tags in my output as follows:

Code:
$output = Links::SiteHTML::display('rc_rank.html', {
RC_Rank => $counter,
RC_Count => $rc_count,
RC_IN => $rc_in,
RC_Hits =>$hits
RC_Title => $title
} );


I am wondering if maybe I can do part of this with a hashref:

row: while ($review = $sth->fetchrow_hashref) {
my $title = $row->{Title}; then tie the rest in somehow... have not selected much with hashref beforeCrazy


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 21, 2002, 10:29 PM
Quote Reply
Re: [Ian] SQL and General Problem with Output In reply to
You probably want to make this a loop:
Code:
my @loop;
while (my $data = $sth->fetchrow_hashref) {
push @loop, $data;
}
$output = Links::SiteHTML::display('rc_rank.html', rank_loop => \@loop }

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] SQL and General Problem with Output In reply to
Hi Yogi, it looks like you were typing while I was editing/thinking... and its nice to see you have a hashref in the select too... so I was on the right track perhaps!

Let me analyse...


EDIT: I think I understand what you are doing... I am going to try thisSmile

Thanks Ivan!


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 21, 2002, 10:33 PM
Post deleted by Ian In reply to

Last edited by:

Ian: Jun 21, 2002, 11:19 PM
Quote Reply
Re: [yogi] SQL and General Problem with Output In reply to
    

Code:
my $topx = shift;
my $lt = $DB->table('Links');
my $output;
my ($rank, $title, $rc_count, $rc_in, $hits); $lt->select_options ('ORDER BY RC_Count DESC, RC_IN DESC, Hits DESC', "LIMIT $topx");
my $sth = $lt->select('Title', 'RC_Count', 'RC_IN', 'Hits'); my @loop;
while (my $data = $sth->fetchrow_hashref) {
push @loop, $data;
}
$output = Links::SiteHTML::display('rc_rank', rank_loop => \@loop );


Gives me error: Not a HASH reference at /s/categories.ca/cgi-bin/admin/Links.pm line 264.

with:

<%loop rank_loop%> in my template. Where to look? The error is reporting in the links.pm... but must be because of a variable mismatch or column mismatch of some sort. I checked all the columns in my select, and they are all correct.Crazy


EDIT: No matter how may times I edit and change this post, some of the lines in my code are not keeping their carriage returns! That is why the last post is deleted, and this did not solve the problem either. It is formatted correct in textpad though....hmmm


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 21, 2002, 11:22 PM
Quote Reply
Re: [yogi] SQL and General Problem with Output In reply to
Quote:
my @loop;
while (my $data = $sth->fetchrow_hashref) {
push @loop, $data;
}

You could also use just:

my $loop = $sth->fetchall_arrayref({});

Which creates an arrayref of hashrefs which the loop tag requires.

Last edited by:

Paul: Jun 22, 2002, 2:31 AM
Quote Reply
Re: [Ian] SQL and General Problem with Output In reply to
Ian you'd need:

$output = Links::SiteHTML::display('rc_rank', { rank_loop => \@loop } );
Quote Reply
Re: [Paul] SQL and General Problem with Output In reply to
Hi Paul,

Thanks very much... I'll try that out. I am still getting a grip of an arrayref/hashref etc. Better than I was, but they still catch me out.

I'll be backWink


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Paul] SQL and General Problem with Output In reply to
Worked it out!


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 22, 2002, 2:33 PM