Hello.

Im getting this error on a product page on my website

Quote

'Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/supremew/public_html/catalog/osc/products_new.php on line 89'

?>
    <tr>
    <td width="<?php echo SMALL_IMAGE_WIDTH + 10; ?>" valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $products_new['products_image'], $products_new['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>'; ?></td>
    <td valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '"><b><u>' . $products_new['products_name'] . '</u></b></a><br>' . TEXT_DATE_ADDED . ' ' . tep_date_long($products_new['products_date_added']) . '<br>' . TEXT_MANUFACTURER . ' ' . $products_new['manufacturers_name'] . '<br><br>' . TEXT_PRICE . ' ' . $products_price; ?></td>
    <!--Start JLG Disable Buy Now and Shopping Cart-->
    <?php
    ?>
    <tr>
    <td width="<?php echo SMALL_IMAGE_WIDTH + 10; ?>" valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $products_new['products_image'], $products_new['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>'; ?></td>
    <td valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '"><b><u>' . $products_new['products_name'] . '</u></b></a><br>' . TEXT_DATE_ADDED . ' ' . tep_date_long($products_new['products_date_added']) . '<br>' . TEXT_MANUFACTURER . ' ' . $products_new['manufacturers_name'] . '<br><br>' . TEXT_PRICE . ' ' . $products_price; ?></td>
    <!--Start JLG Disable Buy Now and Shopping Cart-->
    <?php
    $nononline_items = array();
    $sql = "SELECT products_id FROM products WHERE disable_addtobasket='Y'";
    $result = mysql_query($sql);
    while($id = mysql_fetch_array($result,MYSQL_ASSOC)){
    array_push($nononline_items,$id['products_id']);
    }
    if (in_array($products_new['products_id'],$nononline_items)){
    echo ("<td align=\"right\">". NON_ONLINE_ITEM ."</td>");
    }
    else{
    echo "<td align=\"right\" valign=\"middle\" class=\"main\">";
    echo '<a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $products_new['products_id']) . '">' . tep_image_button('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</a>';
    echo "</td>";
    }
    ?>
    <!--End JLG Disable Buy Now and Shopping Cart-->
    $sql = "SELECT products_id FROM products WHERE disable_addtobasket='Y'";
    $result = mysql_query($sql);
    while($id = mysql_fetch_array($result,MYSQL_ASSOC)){
    array_push($nononline_items,$id['products_id']);
    }
    if (in_array($products_new['products_id'],$nononline_items)){
    echo ("<td align=\"right\">". NON_ONLINE_ITEM ."</td>");
    }
    else{
    echo "<td align=\"right\" valign=\"middle\" class=\"main\">";
    echo '<a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $products_new['products_id']) . '">' . tep_image_button('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</a>';
    echo "</td>";
    }
    ?>
    <!--End JLG Disable Buy Now and Shopping Cart-->

In red is line 89

Can anyone help? I really have no idea what to edit


Thanks.

Do i just paste this code in my php files?

1.
      $query = 'SELECT * FROM `security` LIMIT 0 , 30';
   2.
      $result = mysql_query($query, $conn);
   3.
      if (mysql_numrows($result) == 0)
   4.
      {
   5.
      echo "Result set is EMPTY";
   6.
      } else if (!$result) {
   7.
      echo "Result set is NULL";
   8.
      } else {
   9.
      echo "Result set is VALID";
  10.
      $row = mysql_fetch_assoc($result);
  11.
      $a = array_search($user, $row);
  12.
      echo $a;
  13.
      }

Pretty much, all you need to do is replace the sql with your own and put all of your data handling where I've specified:

$query = '[B]YOUR SQL HERE[/B]';
      $result = mysql_query($query, $conn);
      if (mysql_numrows($result) == 0)
      {
      echo "Result set is EMPTY";
      } else if (!$result) {
      echo "Result set is NULL";
      } else {
      echo "Result set is VALID";
      $row = mysql_fetch_row($result);
      [B]YOUR DATA HANDLING HERE[/B]      
      }

Good luck.

Sorry, Im still a novice, what do you mean by data handling?

I take it my 'SQL' is the database?

Data handling is what you want to do to your data one you've extracted it from the database, display it in a table, perform calculations etc.

Your SQL is the statement you execute to get the data out of the database (eg "SELECT * FROM table_name WHERE condition bla bla bla)

On a side note, osCommerce is one of the most complex third party programs I have had the chance to work with, and if you are a php novice it might be a better idea to cut your teeth on something a little simpler, or at least avoid customising it as much as possible.

This article has been dead for over six months. Start a new discussion instead.