DB structure:
$dbh->do("DROP TABLE IF EXISTS catalog"); $dbh->do("CREATE TABLE catalog (". " id int(11) unsigned NOT NULL auto_increment,". " surname varchar(50) NOT NULL DEFAULT '',". " name varchar(50) NOT NULL DEFAULT '',". " comment varchar(1250) NOT NULL DEFAULT '',". " height varchar(5) NOT NULL DEFAULT '',". " bust varchar(5) NOT NULL DEFAULT '',". " talia varchar(5) NOT NULL DEFAULT '',". " bedra varchar(5) NOT NULL DEFAULT '',". " shoes varchar(5) NOT NULL DEFAULT '',". " hair varchar(50) NOT NULL DEFAULT '',". " lang varchar(250) NOT NULL DEFAULT '',". " educ varchar(250) NOT NULL DEFAULT '',". " m_code varchar(50) NOT NULL DEFAULT '',". " hidden int(1) unsigned NOT NULL DEFAULT 0,". " PRIMARY KEY (id)". ");" ); $dbh->do("DROP TABLE IF EXISTS catalog_links"); $dbh->do("CREATE TABLE catalog_links (". " pid int(1) unsigned NOT NULL DEFAULT 0,". " cid int(11) unsigned NOT NULL DEFAULT 0,". " sort int(11) unsigned NOT NULL DEFAULT 0,". " PRIMARY KEY (pid,cid)". ");" ); $dbh->do("DROP TABLE IF EXISTS images"); $dbh->do("CREATE TABLE images (". " id int(11) unsigned NOT NULL auto_increment,". " pid int(11) unsigned NOT NULL DEFAULT 0,". " ptype varchar(10) NOT NULL DEFAULT '',". " ext varchar(10) NOT NULL DEFAULT '',". " name varchar(50) NOT NULL DEFAULT '',". " main int(1) unsigned NOT NULL DEFAULT 0,". " sort int(11) unsigned NOT NULL DEFAULT 0,". " PRIMARY KEY (id)". ");" ); Query the DB itself:
my $hash = {}; if ($pid) { my @items = (); my $sth = $dbh->prepare("SELECT c.*, i.id as im_id, i.ext FROM catalog c, catalog_links cl, images i WHERE c.hidden=0 AND c.id=cl.cid AND (i.pid=c.id AND i.ptype=? AND i.main=1) AND cl.pid=? ORDER BY cl.sort DESC"); my $rvs = $sth->execute('catalog', $pid) or die "execute: ".$sth->errstr."\n"; while (my $item = $sth->fetchrow_hashref) { $item->{lang} =~ s/,/<br>/g; push(@items, $item); } Thank you very much for the answer. But I still do not have enough understanding how to do this further. As I understand it, in my code from the database, strings that belonged to the same model were taken. Further, the taken lines turned into @items or $ item. Then this code was used to breakdown (how many of these models (or @items) on the page, how many on one line):
if (@items) { my $count = @items; my $count_from = ($curpage-1)*$items_on_top; my $count_to = $count_from+$items_on_top; $count_to = $count if ($count<$count_to); my @items = @items[$count_from .. ($count_to-1)]; if (@items) { my (@it_top, @it_bot) = (); my $cnt = 0; for (my $i=0; $i<$items_on_top; $i++){ if ($i<$items_per_line) { if ($items[$i]) { push(@it_top, $items[$i]); $cnt++; } else { push(@it_top, {sp=>1}) if @it_top; } } else { if ($items[$i]) { push(@it_bot, $items[$i]); } else { push(@it_bot, {sp=>1}) if @it_bot; } } } if (@it_top) { $it_top[0]->{first} = 1; $it_top[-1]->{last} = 1; $hash->{it_top} = \@it_top; } if (@it_bot) { $it_bot[0]->{first} = 1; $it_bot[-1]->{last} = 1; $hash->{it_bot} = \@it_bot; } $hash->{"cols".$cnt} = 1; } if ($count>$items_on_top) { my $pages = (int($count/$items_on_top))+(($count%$items_on_top)>0?1:0); $hash->{nav} = &navigation($curpage, $pages); } } How do I turn your code into the same array? To further had no problems with the output already in the browser. I would be very grateful for the help.