We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34466
    • 19 Posts
    Can anyone tell me what's wrong with this? It maybe as simple as the placing of the {}. Thanks.

    <?php
    mysql_connect(localhost,x,x);
    
    $result = mysql_query('SELECT * FROM x.x');
    
    while($row = mysql_fetch_array( $result )) 
    	$pagetitle = $row['name'];
    	$content = $row['description'];
    	$menutitle = $row['price'];
    	$longtitle = $row['phone_url'];
    	$link_attributes = $row['color'];
    	$introtext = $row['picture'];
    	$description = $row['thumb'];
    	$parent = $row['parent'];
    {
    $fields = array(
        'pagetitle' => $pagetitle,
        'description' => $description,
        'menutitle' => $menutitle,
        'longtitle' => $longtitle,
        'link_attributes' => $link_attributes,
        'introtext' => $introtext,
        'content' => $content,
        'template' => 2,
        'parent' => $parent,
        'published' => 1,
    );
    }
    $response = $modx->runProcessor('resource/create', $fields);
      • 4172
      • 5,888 Posts
      Don't think its a good idea to misuse the resource-fields like that.
      I would rather use TVs for your special fields.
      And:
      Is there a special reason you are using runProcessor and not newObect() + save() ?

      Anyway, does this work?

      <?php
      
      mysql_connect(localhost, x, x);
      
      $result = mysql_query('SELECT * FROM x.x');
      
      while ($row = mysql_fetch_array($result)) {
          $fields = array(
              'pagetitle' => $row['name'],
              'description' => $row['thumb'],
              'menutitle' => $row['price'],
              'longtitle' => $row['phone_url'],
              'link_attributes' => $row['color'],
              'introtext' => $row['picture'],
              'content' => $row['description'],
              'template' => 2,
              'parent' => $parent,
              'published' => 1
              );
          $responses[] = $modx->runProcessor('resource/create', $fields);
      }
      
      


        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 3749
        • 24,544 Posts
        I almost never disagree with Bruno17, but I often recommend using Resource fields for this, if you're sure you won't need them for their original purpose, because the searching and sorting is so much faster and easier. Be sure to check the lengths of those fields in the DB and make sure you're not trying to put anything in them that won't fit.

        I also prefer using the resource/create processor when possible because I think it does a better job of setting the default values of all Resource fields and related objects and does a better job of handling and reporting errors. It also helps you make sure an upgrade to MODX won't mess anything up.

        It is possible, BTW, to set TV values with the resource/create processor, though it's tricky (see the NewsPublisher class code).

          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting