SQL Select Problem

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
tomnoble
Forum Commoner
Posts: 28
Joined: Tue Jun 15, 2010 1:18 pm

SQL Select Problem

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: SQL Select Problem

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply