Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Posts
    7

    Unanswered: 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

  2. #2
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •