Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Programming > Databases - MySQL, SQL, Oracle, Access and others
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-13-2007, 11:16 PM   #1 (permalink)
TylerNZ
Junior Member
 
Join Date: Mar 2007
Posts: 4
Lightbulb multi-column query -> but how to display?

Hi ... brand new newbie here ... I have a mysql query:
Code:
SELECT regions.regionID, regions.name AS state, categories.categoryID, categories.name FROM regions, categories WHERE regions.regionID=categories.regionID
Which returns the values I want:

+++++++++++++++++++++++++++++++++++++++
| regions | state | categoryID | name |
----------------------------------------------------
| NA | National | 1 | Some Category |
| NA | National | 2 | Another Cat. |
| WA | Washing.| 3 | Blahblah |
| WA | Washing.| 7 | Hmmmmm |
| LA | Lou. | 8 | Lahdedah |
---------------------------------------------------

Ok, so NOW I'm confused on how I would display this ... I started with:
Code:
$regionName = $row['state']; while($row = mysql_fetch_array($query)){ do{ $code.='<li>'.$regionName.'</li> <ul>'; $regionName=$row['state']; } while ($regionName!=$row['state']) $code.='<li><a href="./members/?cat='.$row['categoryID'].'&region='.$row['regionID'].'">'.$row['name'].'</a></li>'; }

Obviously that isn't finished ... but can you see what I'm trying to accomplish?
[HTML]<ul>
<li>National</li>
<ul>
<li>Some Category</li>
<li>Another Cat.</li>
</ul>
<li>Washing.</li>
<ul>
<li>Blahblah</li>
<li>Hmmmmm</li>
</ul>
<li>Lou.</li>
<ul>
<li>Ladedah</li>
</ul>
</ul>[/HTML]

Can anyone help me???
TylerNZ is offline   Reply With Quote
Sponsored Links
Old 03-14-2007, 08:18 AM   #2 (permalink)
TylerNZ
Junior Member
 
Join Date: Mar 2007
Posts: 4
Default Re: multi-column query -> but how to display?

Ok, I think I solved it ... altho I bet this isn't the best coding in the world!!! Still open to some criticing:

PHP Code:
$i=0;
        
$previousRegion="";
        while(
$row mysql_fetch_array($query)){ 
            
$regionName $row['state']; 
            
$i++;
            
            if(
$regionName!=$previousRegion){
                if(
$i>1){
                    
$code.="\n\t</ul>";
                }
                
$code.="<li><strong>".$regionName."</strong></li>\n\t<ul>";
            }
            
            
$code.='<li><a href="./members/?cat='.$row['categoryID'].'&region='.$row['regionID'].'">'.$row['name'].'</a></li>'."\n\t";
            
            
$previousRegion $regionName;
        }
        
$code.="\n\t</ul>"
TylerNZ is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 10:33 AM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums