stuck combining while loops

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bruisedghost
Forum Newbie
Posts: 16
Joined: Wed Jan 21, 2009 12:15 am

stuck combining while loops

Post by bruisedghost »

Hi all, basically what I am doing here is creating a while loop with a SQL statement that needs to populate a variable. after the while loop completes and my data bas populated the variable created in the while loop I need to pass that data into an additional select statement that loops again. I cant seem to figure out how to do this and Im sure there is an easier way.

Code: Select all

$query = "SELECT nid FROM ec_transaction_product WHERE txnid =".$txn->txnid;
$query2 = "SELECT body FROM node_revisions WHERE nid =".$noder;
 
 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
if (mysql_num_rows($result) > 0) {
    // yes
    // print them one after another
 
 
//begin while loop
 while($row = mysql_fetch_assoc($result)) {
 
$noder = $row[nid];
print $noder;
}
}
$query2 = "SELECT body FROM node_revisions WHERE nid =".$noder;
 
 
$result = mysql_query($query2) or die ("Error in query: $query. ".mysql_error());
if (mysql_num_rows($results) > 0) {
    // yes
    // print them one after another
 
 
//begin while loop
 while($row = mysql_fetch_assoc($results)) {
 
$description = $row[body];
}
}
mysql_free_result($result);
mysql_free_result($results);

I think that my logic is sound, but it is still not working. if anyone knows of an easier way to do this please let me know Ive been banging my head for the past couple hours trying to figure it out. Thanks!
bruisedghost
Forum Newbie
Posts: 16
Joined: Wed Jan 21, 2009 12:15 am

Re: stuck combining while loops

Post by bruisedghost »

never mind figured it out, Im an idiot!

Code: Select all

 
$query = "SELECT nid FROM ec_transaction_product WHERE txnid =".$txn->txnid;
 
 
 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
if (mysql_num_rows($result) > 0) {
    // yes
    // print them one after another
 
 
//begin while loop
 while($row = mysql_fetch_assoc($result)) {
 
    $noder = $row[nid];
    $query2 = "SELECT body FROM node_revisions WHERE nid =".$noder;
    $results = mysql_query($query2) or die ("Error in query: $query. ".mysql_error());
        if (mysql_num_rows($results) > 0) {
            // yes
            // print them one after another
        while($row = mysql_fetch_assoc($results)) {
        $description = $row[body];
        print $description; 
        }
        }
    }
    }
mysql_free_result($result);
mysql_free_result($results);
 
Post Reply