General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 30th, 2003, 12:32 PM
martekbiz martekbiz is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 1 martekbiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
looping problem

Hi All,

New to this board. Hope to contribute and receive as much as possible.

Here's a current problem Im having.

Code:

PHP Code:
<?php
if ($sort) {

    
$list explode("-"$sort);

}

$test = Array('A-D''D-G''G-J''J-M''M-P''P-S''S-V''V-Y''Y-Z');

foreach (
$test as $group) {
    if (
strtolower ($group) != $sort) {
        
$lgroup strtolower ($group);
        echo 
"<a href=\"patterns.php?sort={$lgroup}\">{$group}</a><br />";
    }
}


$designerQuery db_query("SELECT designer FROM kcs_patterns WHERE designer BETWEEN '".$list[0]."' and '".$list[1]."' GROUP BY designer ORDER BY designer");
while (
$designerResult db_fetch($designerQuery)) {

?>
<img src="Graphics/spacer.gif" width="10" height="1"><a href=""><font class="catalogueSubCatLink"><?php echo $designerResult['designer']; ?> Designers</font></a><br>
<?php

    
}    

?>


The above code is producing results like (assuming A-D was selected):

PHP Code:
 A-D Designers
D
-G Designers
G
-J Designers
J
-M Designers
M
-P Designers
P
-S Designers
S
-V Designers
V
-Y Designers
Y
-Z Designers
Artists Collection The
Barrick Samplers
Bent Creek
Brown House Studio
Butternut Road
Calico Crossroads
Canterbury
Cross My Heart
Crossed Wing Collection 


What I need it to do is (again assuming A-D was selected):

PHP Code:
 A-D Designers

Artists Collection The
Barrick Samplers
Bent Creek
Brown House Studio
Butternut Road
Calico Crossroads
Canterbury
Cross My Heart
Crossed Wing Collection

D
-G Designers
G
-J Designers
J
-M Designers 
M
-P Designers
P
-S Designers
S
-V Designers
V
-Y Designers
Y
-Z Designers 


Or if D-G was selected:

PHP Code:
 A-D

D
-G Designers

Datta Bonnie
Design Connection
Design Connection The
DMC
Donna Gallagher Creative Needlearts
Dragon Dreams
Family Tree The
Fanci That
Full Circle Designs

G
-J Designers
J
-M Designers
M
-P Designers
P
-S Designers
S
-V Designers
V
-Y Designers
Y
-Z Designers 


I've tried a few placements of the foreach loop but nothing seems to work. Anyone have an idea?

Thanks!
Aaron

Reply With Quote
  #2  
Old July 30th, 2003, 01:14 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
You just need to test for selection in your foreach, move the query and while loop into the foreach, and execute them only if the current element is selected. Currently, you're executing your whole foreach loop and then executing your while loop, so it makes sense that you'd get the output of the foreach and then the output of while. To save resources, make sure you execute your query and the resulting while loop only if the current item in the foreach loop is selected.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > looping problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT