2010-10-13 109 views
1

我已经迁移了一些代码,一切正常,直到我在教程中遇到这段代码。因为我有一个自定义模板,所以html和php代码与原始模板有点不同,现在我完全迷失了。迁移两段代码,错误mysql_fetch_array()期望参数1成为资源

这是原来的代码,它应与一个此码下方取代:

<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> 

这是我与原来的(一个以上此代码)来替换代码:

<!-- 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 --> 

这是它产生在我的网站错误:

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

这是行99

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

任何帮助将是巨大的,原谅我的代码的格式,我试图使它尽可能好的,但有些回声线是长。

编辑:

在这里发帖,完整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) { 

线99

回报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; 
    } 
    } 
?> 

第一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 
+0

你能告诉我们围绕99行的代码吗?我的意思是在该行之前有更多行。 '$ db_query'是如何设置的。 – codaddict 2010-10-13 14:35:08

+0

感谢您的回复,我编辑了我的问题。 fyi,图像效果(fancybox)正在运行,它不会做的事情就是从数据库中提取有关产品的信息 – Chris 2010-10-13 14:44:57

+0

“tep_db_fetch_array”在哪里被调用? – codaddict 2010-10-13 14:56:51

回答

1

由于错误信息,你传递到tep_db_fetch_array()的$ db_query显然是不正确设置。某处它被取消,被覆盖,被称为超出范围,或者你在某个参数中有一个错字。

+0

它被严重覆盖。谢谢大家 – Chris 2010-10-13 17:41:18