views:

33

answers:

1

Hello,

I have migrated some codes, all went fine till I encountered this code in the tutorial. Because I have a custome template, the html and php code is a little different from the original template, now I'm totally lost.

This is the original code, which should be replaced with the one beneath this code:

<table cellspacing="0" cellpadding="0" border="0" class="product">
    <tr>
      <td width="103" height="104"><script language="javascript"><!--
document.write('<?php echo '
<a href="javascript:popupWindow(\\\'' . 
tep_href_link(FILENAME_POPUP_IMAGE, 'pID=' . 
$product_info['products_id']) . '\\\')">' 
. tep_image(DIR_WS_IMAGES . 
$product_info['products_image'], addslashes(
$product_info['products_name']), 
SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="0" vspace="0"') . '</a>'; ?>');
//--></script>
<noscript>
<?php echo '<a href="' . tep_href_link(DIR_WS_IMAGES . 
$product_info['products_image']) . '" target="_blank">' . 
tep_image(DIR_WS_IMAGES . 
$product_info['products_image'], 
$product_info['products_name'], 
SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="0" vspace="0"') . '</a>'; ?>
</noscript></td>
        <td width="344" height="104"><br>
            <br style="line-height:5px"><?php echo stripslashes(
$product_info['products_description']); ?>
<br style="line-height:1px;"><br style="line-height:5px;">
        </td>
    </tr>
    <tr>
        <td width="447" height="1" colspan="2">
<img src="images/3_line.gif" alt="" border="0"><br></td>
    </tr>
    <tr>
        <td height="38">
            <br style="line-height:12px"><script language="javascript"><!--
document.write('<?php echo '
<div style=" text-align:center; width:90%;"> 
<a href="javascript:popupWindow(\\\'' 
. tep_href_link(FILENAME_POPUP_IMAGE, 'pID=' . 
$product_info['products_id']) . '\\\')">' 
. TEXT_CLICK_TO_ENLARGE . '</a></div><br style="line-height:2px;">'; ?>');
//--></script>
<noscript>
<?php echo '<div style=" text-align:center; width:90%;">
<a href="' . tep_href_link(DIR_WS_IMAGES . 
$product_info['products_image']) . '" target="_blank">
<br style="line-height:7px">' . TEXT_CLICK_TO_ENLARGE . '</a>
</div>
 <br style="line-height:2px;">'; ?>
</noscript>

        </td>
        <td style=" vertical-align:middle; padding-left:20px;"><strong>
<?=$products_price?></strong><br></td>
    </tr>
</table>

This is the code I had to replace with the original one (the one above this code):

    <!-- Simple multi image addon --> 
<div id="fancy"> 
    <table border="0" cellspacing="0" cellpadding="2" align="right"> 
        <tr> 
            <td align="center" class="smallText"> 

            <?php
  if (strlen($product_info['products_name']) > 
$max_title_length)
    {
      $title = wordwrap(htmlspecialchars($product_info['products_name']), 
$max_title_length, '<br>');
    }
  else
    {
      $title = htmlspecialchars($product_info['products_name']);
    }

  $m_source = '';

  $thumb = (class_exists('oscthumb') && CFG_MASTER_SWITCH == 'On');

  if ($thumb)
    {
      preg_match('/"([^"]+)"/', htmlentities(tep_image(
DIR_WS_IMAGES . 
$product_info['products_image'], '', '', '', '', '', 5), 
   ENT_NOQUOTES), $image);

      $m_source = str_replace('&amp;', '&', $image[1]);
    }

  echo '<a  rel="image_group" title="' . $title . '" href="' . (
$m_source ? $m_source : DIR_WS_IMAGES . 
$product_info['products_image']) . '" 
alt="' . $product_info['products_name'] . '" target="_blank">' . 
tep_image(DIR_WS_IMAGES . $product_info['products_image'], 
   $product_info['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 
'hspace="5" vspace="5"', false, 5) . '
<br /></a>';

  if (!$vertical_format)
    {
      echo '';
      $row = 1;
      reset($products_image_array);
      foreach ($products_image_array as $value)
        {
          if ($thumb)
            {
              $source = '';
              preg_match('/"([^"]+)"/', htmlentities(
tep_image(DIR_WS_IMAGES . $value, '', '', '', '', '', 5), ENT_NOQUOTES), 
$image);
              $source = str_replace('&amp;', '&', $image[1]);
            }
          echo '<a  rel="image_group" title="' . $title . '" href="' . (
$source ? $source : DIR_WS_IMAGES . $value) . '" target="_blank">' . 
tep_image(DIR_WS_IMAGES . $value, $product_info['products_name'], 
TINY_IMAGE_WIDTH, TINY_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . 
  '</a>';
          ++$row;

          if ($row > $image_group)
            {
              echo '<br />';
              $row = 1;
            }
        }
    }

  echo '</td>';

  if ($vertical_format)
    {
      echo '<td>';
      $row = 1;
      reset($products_image_array);

      foreach ($products_image_array as $value)
        {
          if ($thumb)
            {
              $source = '';
              preg_match('/"([^"]+)"/', htmlentities(
tep_image(DIR_WS_IMAGES . $value, '', '', '', '', '', 5), 
ENT_NOQUOTES), $image);
              $source = str_replace('&amp;', '&', $image[1]);
            }

          echo '<a  rel="image_group" title="' . 
$title . '" href="' . ($source ? $source : DIR_WS_IMAGES . $value) . '" 
  target="_blank">' . 
tep_image(DIR_WS_IMAGES . $value, $product_info['products_name'], 
TINY_IMAGE_WIDTH, TINY_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . 
'<br />' . '</a>';
          ++$row;

          if ($row > $image_group)
            {
              echo '</td><td>';
              $row = 1;
            }
        }

      echo '</td>';
    }
?> 

        </tr> 

        <?php
  echo 
'<tr><td class="smallText">' . TEXT_CLICK_TO_ENLARGE . '</td></tr>';
?> 
    </table> 
</div> 
<!-- EOF Simple multi image addon -->

This is the error it produces on my website:

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in.. 
includes/functions/database.php on line 99

This is line 99

function tep_db_fetch_array($db_query) {
    return mysql_fetch_array($db_query, MYSQL_ASSOC);
  }

Any help would be great, excuse me for the formatting of the code, i tried to make it as good as possible, but some echo lines are to long.

Edit:

Posting here, complete database.php

<?php
/*
  $Id: database.php,v 1.21 2003/06/09 21:21:59 hpdl Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  function tep_db_connect(
$server = DB_SERVER, 
$username = DB_SERVER_USERNAME, 
$password = DB_SERVER_PASSWORD, 
$database = DB_DATABASE, 
$link = 'db_link') {
    global $$link;

    if (USE_PCONNECT == 'true') {
      $$link = mysql_pconnect($server, $username, $password);
    } else {
      $$link = mysql_connect($server, $username, $password);
    }

    if ($$link) mysql_select_db($database);

    return $$link;
  }

  function tep_db_close($link = 'db_link') {
    global $$link;

    return mysql_close($$link);
  }

  function tep_db_error(
$query, $errno, $error) { 
    die('<font color="#000000">
<b>' . $errno . ' - ' . $error . '<br><br>' . 
$query . '<br><br><small><font color="#ff0000">
[TEP STOP]</font></small><br><br></b></font>');
  }

  function tep_db_query($query, $link = 'db_link') {
    global $$link;

    if (defined('STORE_DB_TRANSACTIONS') && (
STORE_DB_TRANSACTIONS == 'true')) {
      error_log('QUERY ' . 
$query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
    }

    $result = mysql_query($query, $$link) or 
tep_db_error($query, mysql_errno(), mysql_error());

    if (defined('STORE_DB_TRANSACTIONS') && (
STORE_DB_TRANSACTIONS == 'true')) {
       $result_error = mysql_error();
       error_log('RESULT ' . $result . ' ' . 
$result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
    }

    return $result;
  }

  function tep_db_perform($table, $data, $action = 'insert', 
$parameters = '', $link = 'db_link') {
    reset($data);
    if ($action == 'insert') {
      $query = 'insert into ' . $table . ' (';
      while (list($columns, ) = each($data)) {
        $query .= $columns . ', ';
      }
      $query = substr($query, 0, -2) . ') values (';
      reset($data);
      while (list(, $value) = each($data)) {
        switch ((string)$value) {
          case 'now()':
            $query .= 'now(), ';
            break;
          case 'null':
            $query .= 'null, ';
            break;
          default:
            $query .= '\'' . tep_db_input($value) . '\', ';
            break;
        }
      }
      $query = substr($query, 0, -2) . ')';
    } elseif ($action == 'update') {
      $query = 'update ' . $table . ' set ';
      while (list($columns, $value) = each($data)) {
        switch ((string)$value) {
          case 'now()':
            $query .= $columns . ' = now(), ';
            break;
          case 'null':
            $query .= $columns .= ' = null, ';
            break;
          default:
            $query .= $columns . ' = \'' . tep_db_input($value) . '\', ';
            break;
        }
      }
      $query = substr($query, 0, -2) . ' where ' . $parameters;
    }

    return tep_db_query($query, $link);
  }

  function tep_db_fetch_array($db_query) {

line 99

return mysql_fetch_array($db_query, MYSQL_ASSOC); }

  function tep_db_num_rows($db_query) {
    return mysql_num_rows($db_query);
  }

  function tep_db_data_seek($db_query, $row_number) {
    return mysql_data_seek($db_query, $row_number);
  }

  function tep_db_insert_id() {
    return mysql_insert_id();
  }

  function tep_db_free_result($db_query) {
    return mysql_free_result($db_query);
  }

  function tep_db_fetch_fields($db_query) {
    return mysql_fetch_field($db_query);
  }

  function tep_db_output($string) {
    return htmlspecialchars($string);
  }

  function tep_db_input($string, $link = 'db_link') {
    global $$link;

    if (function_exists('mysql_real_escape_string')) {
      return mysql_real_escape_string($string, $$link);
    } elseif (function_exists('mysql_escape_string')) {
      return mysql_escape_string($string);
    }

    return addslashes($string);
  }

  function tep_db_prepare_input($string) {
    if (is_string($string)) {
      return trim(tep_sanitize_string(stripslashes($string)));
    } elseif (is_array($string)) {
      reset($string);
      while (list($key, $value) = each($string)) {
        $string[$key] = tep_db_prepare_input($value);
      }
      return $string;
    } else {
      return $string;
    }
  }
?>

The first tep_fetch_array

// Simple multi image addon 
$image_group = TINY_IMAGE_GROUP_SIZE; //Number of images to show per row/column
$vertical_format = (ADDITIONAL_IMAGE_FORMAT == 'vertical');
$max_title_length = 40; //Set the maximm length of popup titles before they are broken into multiple lines.
$product_info_query = tep_db_query("select p.products_id, pd.products_name,
pd.products_description, p.products_model, p.products_quantity, p.products_image,
p.products_image_array, pd.products_url, p.products_price, 
p.products_tax_class_id, p.products_date_added, 
p.products_date_available, p.manufacturers_id from " 
. TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where
p.products_status = '1' and p.products_id = '" . (int)
$HTTP_GET_VARS['products_id'] . "' and 
pd.products_id = p.products_id and 
pd.language_id = '" . (int)$languages_id . "'");
    $product_info = tep_db_fetch_array(
$product_info_query);
        $products_image_array = unserialize($product_inf0
['products_image_array']);
    if (!is_array($products_image_array)) $products_image_array = array();
// EOF Simple multi image addon
A: 

Given that error message, the $db_query you're passing in to the tep_db_fetch_array() is obviously not set properly. Somewhere it's getting nulled out, overwritten, referred to out of scope, or you've got a typo in a parameter somewhere.

Marc B
it's badly overwritten. Thank you all for all
Chris