For Each Loops
Posted: Wed Jul 14, 2010 2:00 pm
Hi,
I have the following code which is causing me some issues:
What I want to do is:
Select all the NID's from the drupal_node table, where the type = product.
For each NID found, I want to:
*Get the product title, and product body from the node_revisions table.
*Set tosave[2] to product title
*Set tosave[3] to product body
*Get the SKU code, from the uc_products table where the NID = NID read in for this loop
*set tosave[1] to SKU code read in
*Select all country_id and related sell_prices where the NID = NID read in for this loop
*Read in all the TID's from the term_node table, where the NID = NID read in for this loop
*For each TID, Select the Description from the term_data table
* $Taxonomy = $Taxonomy. "|" . <read in Description>;
Is anyone able to help me?
Kind Regards
Tom
I have the following code which is causing me some issues:
Code: Select all
//Load in all the NID's
$result = mysql_query("SELECT nid FROM drupal_node WHERE type = 'product'"); //just get nid not *
$row = mysql_fetch_array( $result );
print_r($row);
foreach ($row as $info)
{
//Collect all information from the node_revisions table
$revisions = mysql_query("SELECT title, body FROM drupal_node_revisions WHERE nid = '$info'");
$rowrevise = mysql_fetch_array( $revisions );
print_r($rowrevise);
"<br />\n";
//Collect all information from the products table
$skucode = mysql_query("SELECT model FROM drupal_uc_products WHERE nid = '$info'");
$sku = mysql_fetch_array( $skucode );
print_r($sku);
"<br />\n";
//Collect all the prices from the prices table
$prices = mysql_query("SELECT country_id, sell_price FROM drupal_uc_multigeog WHERE nid = '$info'");
$price = mysql_fetch_array( $prices );
print_r($price);
"<br />\n";
//Collect the taxonomy data
$taxid = mysql_query("SELECT tid FROM
drupal_term_node WHERE nid = '$info'");
$taxs = mysql_fetch_array( $taxid );
print_r($taxs);
foreach ($taxs as $taxs['tid'] => $id)
{
$taxname = mysql_query("SELECT description FROM
drupal_term_data WHERE tid = '$id'");
$taxdesc = mysql_fetch_array( $taxname );
$Taxonomy = $Taxonomy. "|" . $taxdesc[0];
}
if ( $Taxonomy[0] == "|" ) $Taxonomy = substr($Taxonomy, 1);
echo $Taxonomy;Select all the NID's from the drupal_node table, where the type = product.
For each NID found, I want to:
*Get the product title, and product body from the node_revisions table.
*Set tosave[2] to product title
*Set tosave[3] to product body
*Get the SKU code, from the uc_products table where the NID = NID read in for this loop
*set tosave[1] to SKU code read in
*Select all country_id and related sell_prices where the NID = NID read in for this loop
*Read in all the TID's from the term_node table, where the NID = NID read in for this loop
*For each TID, Select the Description from the term_data table
* $Taxonomy = $Taxonomy. "|" . <read in Description>;
Is anyone able to help me?
Kind Regards
Tom