Page 1 of 1

SQL Select Problem

Posted: Thu Jul 08, 2010 2:10 pm
by tomnoble
HI, I am trying to select the "NID" value from the "Drupal_Node" table and return it when the title = a variable.

Here is the code I am having problems with:

Code: Select all

$file_handle = fopen("Product Database.csv", "r");
        
        $Counter = 1;
        
        while (!feof($file_handle)) {
          $product_information = fgetcsv($file_handle);
If ($product_information[0] != "SKU"){          
$nid = mysql_query("SELECT nid FROM drupal_node WHERE title = $product_information[2]"); //just get nid not *

	//Insert data into the Drupal_uc_multigeog table
            mysql_query("INSERT INTO drupal_uc_multigeog
            VALUES ($nid, '946', '0.000', '0.000', $product_information[4], 'N;')");
            mysql_query("INSERT INTO drupal_uc_multigeog
            VALUES ($nid, '930', '0.000', '0.000', $product_information[5], 'N;')");
            mysql_query("INSERT INTO drupal_uc_multigeog
            VALUES ($nid, '960', '0.000', '0.000', $product_information[6], 'N;')");
            mysql_query("INSERT INTO drupal_uc_multigeog
            VALUES ($nid, '915', '0.000', '0.000', $product_information[7], 'N;')");
            mysql_query("INSERT INTO drupal_uc_multigeog
            VALUES ($nid, '900', '0.000', '0.000', $product_information[8], 'N;')");
echo $product_information[2];
echo $nid;
echo $product_information[4];
echo $product_information[5];

         $Counter ++; 
        }  
}     
E.G I am passing in the value "product 1", I want to select the NID for "product1" from the db and run the code accordingly. Any ideas why the above doesnt achieve this? Ignore the echos, they are there for test purposes.

It is just getting the nid value into $nid that is going wrong.

Kind Regards

Tom

Re: SQL Select Problem

Posted: Thu Jul 08, 2010 2:38 pm
by AbraCadaver
Look at http://us3.php.net/mysql-query to see what it returns. Then check out a tutorial to see how to get data from a query.