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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone help?

Status
Not open for further replies.

qrichou

Programmer
Joined
Mar 1, 2007
Messages
2
Location
GB
Hi all,

I have some code i use for overall best sellers i now want to break it down per section and i have written the SQL to do this but the Perl code isnt working how i want it to. I want the items to be on one row but instead its printing 5 rows. Can anyone help?

Here is my code:-
#######################################################################
# ste_prod_dispbestww #
#######################################################################

sub ste_prod_dispbestww {

&initialize_sub_add('sub ste_prod_dispbestww');

$sql_statement = "

SELECT TOP 5 *
from
VIEWBestSellerHold
WHERE product_GMC_Cat = 'WW'
Order by countitems desc

";

my @newdisp = database_call('product','SELECT',$sql_statement);

foreach $row(@newdisp) {

($product_id,$product_name) = @$row;

$seo_item_url = ste_seo_make_url('item', $product_name, $product_id);

print <<ENDOFTEXT;
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="pickhwood" colspan="6">&nbsp;&nbsp;&nbsp;&nbsp;Woodworking Best Sellers</td>
</tr>
<tr>
<td class="pickwoodmagl"><a href="$seo_item_url"><img src="/test_ccp51/media/images/product_category/$product_id.jpg" width="105" border="0" alt="Woodworking"></a><br>
<a href="$seo_item_url" class="mainmenu"><b>$product_name</b></a></td>
<td class="pickwoodmag"><a href="$seo_item_url"><img src="/test_ccp51/media/images/product_category/$product_id.jpg" width="105" border="0" alt="Woodworking"></a>
<a href="$seo_item_url" class="mainmenu"><b>$product_name</b><br><br></a></td>
<td colspan="2" class="pickwoodmag"><a href="$seo_item_url"><img src="/test_ccp51/media/images/product_category/$product_id.jpg" width="105" border="0" alt="Woodworking"></a>
<a href="$seo_item_url" class="mainmenu"><b>$product_name</b><br><br></a></td>
<td class="pickwoodmag"><a href="$seo_item_url"><img src="/test_ccp51/media/images/product_category/$product_id.jpg" width="105" border="0" alt="Woodworking"></a>
<a href="$seo_item_url" class="mainmenu"><b>$product_name</b><br><br></a></td>
<td class="pickwoodmagr"><a href="$seo_item_url"><img src="/test_ccp51/media/images/product_category/$product_id.jpg" width="105" border="0" alt="Woodworking"></a>
<a href="$seo_item_url" class="mainmenu"><b>$product_name</b><br><br></a></td>
</tr>
</table>
ENDOFTEXT

} ######### End of foreach statement.

&initialize_sub_remove('sub ste_prod_dispbestww');

} ######### End of subroutine.
 
Look at your foreach loop:

Code:
foreach $row(@newdisp) {

($product_id,$product_name) = @$row;

$seo_item_url = ste_seo_make_url('item', $product_name, $product_id);

print <<ENDOFTEXT;
[COLOR=red]<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="pickhwood" colspan="6">&nbsp;&nbsp;&nbsp;&nbsp;Woodworking Best Sellers</td>
</tr>
<tr>
<td class="pickwoodmagl"><a href="$seo_item_url"><img src="/test_ccp51/media/images/product_category/$product_id.jpg" width="105" border="0" alt="Woodworking"></a><br>
<a href="$seo_item_url" class="mainmenu"><b>$product_name</b></a></td>
<td class="pickwoodmag"><a href="$seo_item_url"><img src="/test_ccp51/media/images/product_category/$product_id.jpg" width="105" border="0" alt="Woodworking"></a>
<a href="$seo_item_url" class="mainmenu"><b>$product_name</b><br><br></a></td>
<td colspan="2" class="pickwoodmag"><a href="$seo_item_url"><img src="/test_ccp51/media/images/product_category/$product_id.jpg" width="105" border="0" alt="Woodworking"></a>
<a href="$seo_item_url" class="mainmenu"><b>$product_name</b><br><br></a></td>
<td class="pickwoodmag"><a href="$seo_item_url"><img src="/test_ccp51/media/images/product_category/$product_id.jpg" width="105" border="0" alt="Woodworking"></a>
<a href="$seo_item_url" class="mainmenu"><b>$product_name</b><br><br></a></td>
<td class="pickwoodmagr"><a href="$seo_item_url"><img src="/test_ccp51/media/images/product_category/$product_id.jpg" width="105" border="0" alt="Woodworking"></a>
<a href="$seo_item_url" class="mainmenu"><b>$product_name</b><br><br></a></td>
</tr>
</table>[/color]
ENDOFTEXT

}

For each item in @newdisp, a full <table> and <tr> all the way up to the closing </tr></table> is printed. This is why you're getting one "row" for every item in the array; you're telling the code to print out a table foreach $row in @newdisp.

If you want them to be all in one row, try printing the "<table><tr>" part before the foreach loop, then print "</tr></table> after the loop, and have the loop itself only print out the <td>..</td> bits for each item in the array.

-------------
Cuvou.com | The NEW Kirsle.net
 
Oh i see what you mean, i have re coded it like your sugestion and it works fine thank you :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top