Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Looping and counting

by htmanning (Scribe)
on Apr 04, 2012 at 01:30 UTC ( #963344=note: print w/ replies, xml ) Need Help??


in reply to Re: Looping and counting
in thread Looping and counting

Thanks. grabbing only the first 50 is how I normally do it, but I didn't write this script so I'm a bit lost. Here's more code to see if it makes it clearer. This is the skeleton as I've ripped out a bunch of variable setting.

$filebase = "news"; $num_records = 10; $SQL = "SELECT * FROM $content_table WHERE contenttype = 'video' ORDER + BY dateadded DESC, ID DESC"; for ($n=1; $n<=$num_records; $n++) { $pointer = $sth->fetchrow_hashref; $title = $pointer->{'title'}; $main_list2 = $main_list2 . "$title"; print outfile1 "$main_list2"; } $filebase = "morenews"; $num_records = 40; for ($n=1; $n<=$num_records; $n++) { $pointer = $sth->fetchrow_hashref; $title = $pointer->{'title'}; $main_list2 = $main_list2 . "$title"; print outfile2 "$main_list2"; }
As you can see, it loops through and adds another $title to $main_list2. No matter what if statement I put before $main)list2, it doesn't work. I had it like you suggested but no dice. What I'm ending up with is the first 10 titles on page 1, then the first 10 titles, plus the first 40 titles on page 2. Thanks.


Comment on Re^2: Looping and counting
Download Code
Re^3: Looping and counting
by Riales (Hermit) on Apr 04, 2012 at 01:44 UTC

    Put this between your two for loops:

    $main_list2 = '';

    But seeing as you have have a $main_list2, why don't you use $main_list1 in the first for loop instead?

    Also, probably want to have a "\n" between your titles:

    $main_list2 .= "$title\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://963344]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2014-09-22 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (177 votes), past polls