Simple Machines Community Forum

Archived Boards and Threads... => Archived Boards => Mambo Bridge Support => Aiheen aloitti: silentz - maaliskuu 29, 2006, 10:20:51 AP

Otsikko: My simple little mod breaks mod_smfRecent_posts... why?
Kirjoitti: silentz - maaliskuu 29, 2006, 10:20:51 AP
Hi there,

I've put together a little (GPL  :)) mod to display a random oscommerce product in Joomla, but it seems to cause an error message in mod_smfRecent_posts anytime (and only) when my mod appears before mod_smfRecent_posts in the template.

The error message is:
LainaaWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/*****/public_html/joomladir/modules/mod_smfRecentPosts.php on line 19

Can anyone see any way mod_smfRecent_posts / my mod could be altered so they could both live together in peace and harmony?

I've pasted the code below for the main file. It's tiny and very simple being my first ever. Feel free to use, if of use.

silent z

<?php
// mod_random_oSc_product for Joomla, based on v1.2 of "Randomise anywhere" by [email protected], original version by [email protected]
$db_server$params->get'db_server''localhost' );
$db_user $params->get'db_user''' );
$db_pass $params->get'db_pass''' );
$db_name $params->get'db_name''' );
$domain_name $params->get'domain_name''0' );
$catalogue_folder_name $params->get'catalogue_folder_name''catalogue' );
$site_title $params->get'site_title''0' );
$image_width $params->get'image_width''' );
$image_height $params->get'image_height''' );
$num_products $params->get'num_products''1' );
$prod_col $params->get'prod_col''1' );
$table_width $params->get'table_width''100' );
$table_align $params->get'table_align''center' );
$table_cspace $params->get'table_cspace''1' );
$table_cpadd $params->get'table_cpadd''1' );
$product_price_show $params->get'product_price_show''1' );
$product_info_link_show $params->get'product_info_link_show''1' );
$product_buy_link_show $params->get'product_buy_link_show''1' );
$product_name_show $params->get'product_name_show''1' );
$product_price_show $params->get'product_price_show''1' );
$product_image_show $params->get 'product_image_show''1' );
$show_tax_inc $params->get'show_tax_inc''1' );
$this_month $params->get'this_month''70' );
?>

<?php
// create connection
$connection mysql_connect("$db_server","$db_user","$db_pass")
    or die(
"Couldn't make connection. $db_server,$db_user,$db_pass");

// select database
$db mysql_select_db("$db_name"$connection)
  or die(
"Couldn't select database.");

// create SQL statement
if (rand(0,100)>$this_month) {
$sql "SELECT * FROM `products` where products_status = '1' ORDER BY RAND() LIMIT 1";
} else {
$sql "SELECT * FROM `products` where products_status = '1' and month(products_date_added) = month(now()) ORDER BY RAND() LIMIT 1";
}

// execute SQL query and get result
$sql_result mysql_query($sql,$connection)
    or die(
"Couldn't execute quasery.");

// format results by row
$row mysql_fetch_array($sql_result);
$products_id $row["products_id"];
$products_price $row["products_price"];
$products_model $row["products_model"];
$products_image $row["products_image"];
$tax $row['products_tax_class_id'];

//where p.products_status = '1' and month(p.products_date_added) = month(now())
$sql2 "SELECT `products_name` FROM `products_description` WHERE products_id = '$products_id' LIMIT 1";

//$sql2 = "SELECT `products_name` FROM `products_description` WHERE products_id = '$products_id' LIMIT 1";
$sql2_result mysql_query($sql2,$connection)
    or die(
"Couldn't execute query.");
$row2 mysql_fetch_array($sql2_result);
$products_name $row2["products_name"];
$products_image_replace str_replace("./""/"$products_image);

if (
$show_tax_inc == 1) {
$products_price_replace sprintf("%.2f", ($tax*.1 $products_price) + $products_price 0.0049) . " inc GST";
} else {
$products_price_replace substr($products_price,0,strlen($products_price)-2);
}

if (
$product_image_show == "1") {

echo 
"<img src=\"http://$domain_name/$catalogue_folder_name/images/$products_image_replace\" width=\"$image_width\" height=\"$image_height\" border=\"0\"><br>";
}

if (
$product_name_show == "1") {
echo 
"$products_name";
}

if (
$product_price_show == "1") {
echo 
"<br>\$$products_price_replace";
}

if (
$product_buy_link_show == "1") {
echo 
"<br><a href='http://$domain_name/$catalogue_folder_name/index.php?option=com_wrapper_extended&page=$domain_name/$catalogue_folder_name/index.php?products_id=$products_id?action=buy_now'><b><img src='http://$domain_name/$catalogue_folder_name/includes/languages/english/images/buttons/button_buy_now.gif'></b></font></a></td>";
}
if (
$product_info_link_show == "1") {        
echo 
"<br><a href ='http://$domain_name/$catalogue_folder_nameindex.php?option=com_wrapper_extended&page=$domain_name/$catalogue_folder_name/product_info.php?products_id=$products_id'>Learn More</a>";
}

// free resources and close connection
mysql_free_result($sql_result);
mysql_close($connection);
?>
Otsikko: Re: My simple little mod breaks mod_smfRecent_posts... why?
Kirjoitti: Kindred - maaliskuu 29, 2006, 11:19:08 AP
because you are using identical variable names to the ones used in SMF...
(db-name, etc)
Otsikko: Re: My simple little mod breaks mod_smfRecent_posts... why?
Kirjoitti: silentz - maaliskuu 30, 2006, 07:09:07 AP
That would do it... Thx Kindred. I'll change them immediately. :)
Otsikko: Re: My simple little mod breaks mod_smfRecent_posts... why?
Kirjoitti: silentz - maaliskuu 31, 2006, 01:37:51 AP
Well, I prefixed every single variable with osc_, (and fixed a rather large security hole) but still the same error msg...  ???

Anyone have any ideas why mod_smfRecent_posts would be broken by my code? Especially odd is that the line referred to (19) is only the following code:

$sublength = $params->get( 'sublength' );

The code in my mod is:

<?php
// Based on v1.2 of "Randomise anywhere" by [email protected], original version by [email protected]
$osc_db_server$params->get'osc_db_server''localhost' );
$osc_db_user $params->get'osc_db_user''' );
$osc_db_pass $params->get'osc_db_pass''' );
$osc_db_name $params->get'osc_db_name''' );
$osc_domain_name $params->get'osc_domain_name''0' );
$osc_catalogue_folder_name $params->get'osc_catalogue_folder_name''catalogue' );
$osc_site_title $params->get'osc_site_title''0' );
$osc_image_width $params->get'osc_image_width''' );
$osc_image_height $params->get'osc_image_height''' );
$osc_num_products $params->get'osc_num_products''1' );
$osc_prod_col $params->get'osc_prod_col''1' );
$osc_table_width $params->get'osc_table_width''100' );
$osc_table_align $params->get'osc_table_align''center' );
$osc_product_price_show $params->get'osc_product_price_show''1' );
$osc_product_info_link_show $params->get'osc_product_info_link_show''1' );
$osc_product_buy_link_show $params->get'osc_product_buy_link_show''1' );
$osc_product_name_show $params->get'osc_product_name_show''1' );
$osc_product_price_show $params->get'osc_product_price_show''1' );
$osc_product_image_show $params->get 'osc_product_image_show''1' );
$osc_show_tax_inc $params->get'osc_show_tax_inc''1' );
$osc_this_month $params->get'osc_his_month''70' );
?>

<?php
// create connection
$osc_connection mysql_connect("$osc_db_server","$osc_db_user","$osc_db_pass")
    or die(
"Couldn't make connection.");

// select database
$osc_db mysql_select_db("$osc_db_name"$osc_connection)
  or die(
"Couldn't select database. $osc_connection");

// create SQL statement
if (rand(0,100)>$osc_this_month) {
$osc_sql "SELECT * FROM `products` where products_status = '1' ORDER BY RAND() LIMIT 1";
} else {
$osc_sql "SELECT * FROM `products` where products_status = '1' and month(products_date_added) = month(now()) ORDER BY RAND() LIMIT 1";
}

// execute SQL query and get result
$osc_sql_result mysql_query($osc_sql,$osc_connection)
    or die(
"Couldn't execute quasery.");

// format results by row
$osc_row mysql_fetch_array($osc_sql_result);
$osc_products_id $osc_row["products_id"];
$osc_products_price $osc_row["products_price"];
$osc_products_model $osc_row["products_model"];
$osc_products_image $osc_row["products_image"];
$osc_tax $osc_row['products_tax_class_id'];

//where p.products_status = '1' and month(p.products_date_added) = month(now())
$osc_sql2 "SELECT `products_name` FROM `products_description` WHERE products_id = '$osc_products_id' LIMIT 1";

//$osc_sql2 = "SELECT `products_name` FROM `products_description` WHERE products_id = '$osc_products_id' LIMIT 1";
$osc_sql2_result mysql_query($osc_sql2,$osc_connection)
    or die(
"Couldn't execute query.");
$osc_row2 mysql_fetch_array($osc_sql2_result);
$osc_products_name $osc_row2["products_name"];
$osc_products_image_replace str_replace("./""/"$osc_products_image);

if (
$osc_show_tax_inc == 1) {
$osc_products_price_replace sprintf("%.2f", ($osc_tax*.1 $osc_products_price) + $osc_products_price 0.0049) . " inc GST";
} else {
$osc_products_price_replace substr($osc_products_price,0,strlen($osc_products_price)-2);
}

if (
$osc_product_image_show == "1") {

echo 
"<img src=\"http://$osc_domain_name/$osc_catalogue_folder_name/images/$osc_products_image_replace\" width=\"$osc_image_width\" height=\"$osc_image_height\" border=\"0\"><br>";
}

if (
$osc_product_name_show == "1") {
echo 
"$osc_products_name";
}

if (
$osc_product_price_show == "1") {
echo 
"<br>\$$osc_products_price_replace";
}


if (
$osc_product_buy_link_show == "1") {
echo 
"<br><a href=$osc_mosConfig_live_site . '/index.php?option=com_wrapper_extended&page=$osc_domain_name/$osc_catalogue_folder_name/index.php?products_id=$osc_products_id?action=buy_now'><b><img src='http://$osc_domain_name/$osc_catalogue_folder_name/includes/languages/english/images/buttons/button_buy_now.gif'></b></font></a>";
}
if (
$osc_product_info_link_show == "1") {        
echo 
"<br><a href =$osc_mosConfig_live_site . '/index.php?option=com_wrapper_extended&page=$osc_domain_name/$osc_catalogue_folder_name/product_info.php?products_id=$osc_products_id'>Learn More</a>";
}

// free resources and close connection
mysql_free_result($osc_sql_result);
mysql_close($osc_connection);
?>
Otsikko: Re: My simple little mod breaks mod_smfRecent_posts... why?
Kirjoitti: Orstio - maaliskuu 31, 2006, 08:34:04 IP
You didn't switch back to the Joomla database at the end of your module:

mysql_select_db($mosConfig_db);
Otsikko: Re: My simple little mod breaks mod_smfRecent_posts... why?
Kirjoitti: silentz - huhtikuu 03, 2006, 09:31:19 AP
Bingo. That was it.

Thanks all. mod_random_product and mod_smfRecentPosts are now living together in peace and harmony.  ;D
Otsikko: Re: My simple little mod breaks mod_smfRecent_posts... why?
Kirjoitti: molok - huhtikuu 05, 2006, 05:43:42 IP
Lainaus käyttäjältä: silentz - huhtikuu 03, 2006, 09:31:19 AP
Bingo. That was it.

Thanks all. mod_random_product and mod_smfRecentPosts are now living together in peace and harmony.  ;D

Hello,

can you share your module? this would help me a lot.

cheers

Molok