If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > newbie: can you nest mysql_fetch commands?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-10-05, 23:12
blakekr blakekr is offline
Registered User
 
Join Date: Jan 2005
Posts: 7
newbie: can you nest mysql_fetch commands?

As in, mysql_fetch_array or mysql_fetch_assoc?

I've tried nesting them but I only get one row to display for the outermost command. (But maybe I'm screwing up somewhere else).

If you can't, or shouldn't, nest them, how can I assign all the values of all the rows of one mysql_fetch(whatever) to an array to use later on? I've googled and googled on this and I just can't seem to find an example.

Eyes crossing ...

(Eating half a bag of fig newtons has not helped; this must be tough!)

I know this is incorrect, but to grab a bit of code from my rats-nest of a window:

Code:
while ($value = mysql_fetch_assoc($result)) {
  $cat_array[] = $value;
}
Maybe you can see what I'm trying to do here ...

Oh heck, let me give you the whole mess and maybe this one tiny part of my code will look nice when I'm done. This has the nested mysql_fetch commands that don't seem to work.
---
Code:
while ($prod = mysql_fetch_array($prod_result)) {
  $match = 0;
  while ($cat = mysql_fetch_array($cat_result)) {
     $search_term = split(" ", $cat[1]);
     foreach ($search_term as $term) {
        echo "NAME: " . $term . ", " . $prod[1] . "\n";
        if (eregi($term, $prod[1])) {
                $match=1;
        }
     }
     if ($match == 0) {  /// now search description
      foreach ($search_term as $term) {
        if (eregi($term, $prod[2])) {
                $match=1;
        }
      }
     } // end search description
  } // end while categories

  if ($match == 1) {  // Write to prod_categories
     $query="INSERT INTO prod_categories (prod_id, cat_id) VALUES ($prod[0], $cat[0])";
     mysql_query($query) or die(mysql_error());
  }
} // end while products
Reply With Quote
  #2 (permalink)  
Old 01-11-05, 11:57
blakekr blakekr is offline
Registered User
 
Join Date: Jan 2005
Posts: 7
Hey, I managed to cobble together a solution by shoving the category bits into an array, maybe not graceful, but it works.

Thanks for reading!
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On