Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 2nd, 2006, 11:46 AM
moracom's Avatar
moracom moracom is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 220 moracom User rank is Sergeant Major (2000 - 5000 Reputation Level)moracom User rank is Sergeant Major (2000 - 5000 Reputation Level)moracom User rank is Sergeant Major (2000 - 5000 Reputation Level)moracom User rank is Sergeant Major (2000 - 5000 Reputation Level)moracom User rank is Sergeant Major (2000 - 5000 Reputation Level)moracom User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 15 h 33 m 22 sec
Reputation Power: 39
Send a message via MSN to moracom Send a message via Yahoo to moracom
Loop within a loop

I have this database that has 2 tables.
I have this PHP script that will pull data from table 1 and it will loop itself until it retrieves all the records that I need. The second table contains records that belong to a specific record in table 1. I thought that by scripting my first loop and then adding a loop withing the first loop that will call upon the second table will retrieve all the records from table 1 and all the records from table 2 that corresponds to the records in table 1. What happens is that the script will only pull one record from table 1 and one record from table 2 and then it dies.
It's a long script but here it is. All the help that I can get will be great.
PHP Code:
<?
$hostname 
"localhost";
    
$dbName "x";        
    
$username "xx";
    
$password "xxx";
    
/* Connecting, selecting database */
    
$dbh3=mysql_connect ($hostname$username$password)
        or die(
"Could not connect");
    
mysql_select_db($dbName) or die("Could not select database");
    
/* Performing SQL query */
    
$query "SELECT * tbl_Departments WHERE City = "Boston";
    $result = mysql_query($query) or die("
Query failed pulling the data");
    // Determine the number of applicants 
    $number = mysql_numrows($result);
// Print the relevant information
print  "
<table width=100border=0 cellpadding=3 cellspacing=0>
    <
tr>
        <
td width=100align=left valign=top><strong>Small</strong></td>
    </
tr>
</
table>";
If ($number == "
0"){
print "
No offices in this size.";
}else{
print "
<table width=100border=0 cellpadding=10 cellspacing=0>";
     for($i=0; $i<$number; $i++) {
    $DepartmentID = mysql_result($result, $i,  "
DepartmentID");
    $DNumberPartners = mysql_result($result, $i,  "
DNumberPartners");
    $DNumberAssoc = mysql_result($result, $i,  "
DNumberAssoc");
    $DNumberCounsel = mysql_result($result, $i,  "
DNumberCounsel");
    $DKnownFor = mysql_result($result, $i,  "
DKnownFor");
    $DTidBit = mysql_result($result, $i,  "
DTidBit");
    $DTotalAttys = mysql_result($result, $i,  "
DTotalAttys");
     /* print even-numbered rows with a grey background, 
           odd-numbered with a blue background */ 
        if ($i%2 == 0) {
        print  "
<tr>";
        } else {
        print  "
<tr>";
        }
    print  "
<td width=100align=left valign=top>";?>

<table bgcolor="
#000000" width=100% border=0 cellpadding=3 cellspacing=3>
    
<tr>
        <
td bgcolor="#ffffff" width=100align=left valign=top>Group has <?echo $DTotalAttys;?> attorneys with <?echo $DNumberPartners;?> partners, <?echo $DNumberAssoc;?> associates, and <?echo $DNumberCounsel;?> of counsel.</td>
    </tr>
</table>

<table bgcolor="#000000" width=100% border=0 cellpadding=3 cellspacing=3>
    <tr>
        <td bgcolor="#ffffff" width=100% align=left valign=top>
<?//Second loop to second table Starts here?>
<?$hostname 
"localhost";
    
$dbName "x";        
    
$username "xx";
    
$password "xxx";
    
/* Connecting, selecting database */
    
$dbh=mysql_connect ($hostname$username$password)
        or die(
"Could not connect");
    
mysql_select_db($dbName) or die("Could not select database");
        
/* Performing SQL query */
    
$query "SELECT * FROM tbl_AOF WHERE ADepartmentID = '$DepartmentID'";
    
$result mysql_query($query) or die("Query failed pulling the data");
    
// Determine the number of applicants 
    
$number mysql_numrows($result);
// Print the relevant information
print "They do a mix of ";
     for(
$i=0$i<$number$i++) {
    
$AOFDesc mysql_result($result$i,  "AOFDesc");
     
/* print even-numbered rows with a grey background, 
           odd-numbered with a blue background */ 
        
if ($i%== 0) {
        print  
"";
        } else {
        print  
"";
        }
    print  
"$AOFDesc, ";?>

<?    print    "";        
}
print  
".";?>
<?
//Second loop to second table Ends here?>
        </td>
    </tr>
</table>

<?    print    "</td></tr>";        
}
print  
"</table>";
//end of the $number = "0"
    /* Free resultset */
    
mysql_free_result($result);

    
/* Closing connection */
    
mysql_close($dbh);
//Small ends here?>
__________________
If I have been of useful help please don't hesitate to provide me with some Reputation points

Be in Control of your Data and get it your way. Customized Web Applications.

Reply With Quote
  #2  
Old October 2nd, 2006, 10:39 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 19 m 36 sec
Reputation Power: 181
Why this was in the asp forum is beyond me, moved.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Loop within a loop


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