Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with looping through records 1

Status
Not open for further replies.

tviman

Programmer
Jul 25, 2002
2,123
0
0
US
Hi all,

Having an issue with looping through the records of a data table and rendering them onto a web page. In this case, there are 4 records in the table.

This is the code I'm trying to use:

@row = $sth->fetchrow_array;

foreach $row (@row){
print<<EOF;
acctnbr = $row[0]<br>
inv_nbr = $row[1]<br>
inv__date = $row[2]<br>
inv_amt = $row[3]<br>
proj_type = $row[4]<br>
pay_month = $row[5]<br>
EOF

}

This is the result:

acctnbr = 9999
inv_nbr = 3119
inv__date = 2011-01-01
inv_amt = 150
proj_type = M
pay_month = 01
acctnbr = 9999
inv_nbr = 3119
inv__date = 2011-01-01
inv_amt = 150
proj_type = M
pay_month = 01
acctnbr = 9999
inv_nbr = 3119
inv__date = 2011-01-01
inv_amt = 150
proj_type = M
pay_month = 01
acctnbr = 9999
inv_nbr = 3119
inv__date = 2011-01-01
inv_amt = 150
proj_type = M
pay_month = 01
acctnbr = 9999
inv_nbr = 3119
inv__date = 2011-01-01
inv_amt = 150
proj_type = M
pay_month = 01
acctnbr = 9999
inv_nbr = 3119
inv__date = 2011-01-01
inv_amt = 150
proj_type = M
pay_month = 01

Each "grouping" is the first record! What am I missing to get this to iterate through the records?

Thanks for your help!

 
>@row = $sth->fetchrow_array;
>foreach $row (@row){
> etc etc...
>}

This instead (it moves while fetching):
[tt]
while (my @row=$sth->fetchrow_array()) {
#etc etc...
}
[/tt]
 
tsuji,

THANK YOU for turning on the light! Works great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top