聯成電腦技術論壇

 找回密碼
 註冊
搜索
查看: 1651|回復: 1

[求助] Warning: mysql_fetch_assoc(): 10 is not a valid MySQL result resource

[複製鏈接]
發表於 2011-4-15 13:09:54 | 顯示全部樓層 |閱讀模式
各位前輩大大~

頁面出現~Warning: mysql_fetch_assoc(): 10 is not a valid MySQL result resource
這是什麼意思啊~
程式碼如下:<?php require_once('Connections/conn_web.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_web_search = 5;
$pageNum_web_search = 0;
if (isset($_GET['pageNum_web_search'])) {
  $pageNum_web_search = $_GET['pageNum_web_search'];
}
$startRow_web_search = $pageNum_web_search * $maxRows_web_search;

$colname_web_search = "-1";
if (isset($_GET['keyword'])) {
  $colname_web_search = $_GET['keyword'];
}
$colname2_web_search = "-1";
if (isset($_GET['keyword'])) {
  $colname2_web_search = $_GET['keyword'];
}
mysql_query("SET NAMES 'utf8'");
mysql_select_db($database_conn_web, $conn_web);
$query_web_search = sprintf("SELECT p_id, p_name, p_price, p_pic, p_content FROM shop2 WHERE ( p_name LIKE %s OR p_content LIKE %s ) AND p_open = 'Y' ORDER BY p_id ASC", GetSQLValueString("%" . $colname_web_search . "%", "text"),GetSQLValueString("%" . $colname2_web_search . "%", "text"));
$query_limit_web_search = sprintf("%s LIMIT %d, %d", $query_web_search, $startRow_web_search, $maxRows_web_search);
$web_search = mysql_query($query_limit_web_search, $conn_web) or die(mysql_error());
$row_web_search = mysql_fetch_assoc($web_search);

if (isset($_GET['totalRows_web_search'])) {
  $totalRows_web_search = $_GET['totalRows_web_search'];
} else {
  $all_web_search = mysql_query($query_web_search);
  $totalRows_web_search = mysql_num_rows($all_web_search);
}
$totalPages_web_search = ceil($totalRows_web_search/$maxRows_web_search)-1;

$queryString_web_search = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_web_search") == false &&
        stristr($param, "totalRows_web_search") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_web_search = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_web_search = sprintf("&totalRows_web_search=%d%s", $totalRows_web_search, $queryString_web_search);
?>
<? session_start();?>
<? $i=$startRow_web_search+1;?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta http-equiv="Content-Language" content="zh-tw" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="" />
<link href="web.css" rel="stylesheet" type="text/css" />
<script src="ie6png.js" type="text/javascript"></script>
</head>

<body>
<?php include("header.php"); ?>
<div id="main">
  <div id="main1"></div>
  <div id="main2">
      <? include("leftzone.php")?>
  </div>
  <div id="main3">
  <div align="center">
  搜尋關鍵字:<span class="font_red"> &nbsp;<?php echo $_GET['keyword']; ?> &nbsp;</span>
  &nbsp;&nbsp;搜尋結果:相關商品共<span class="font_red"> &nbsp; &nbsp;<?php echo $totalRows_web_search ?></span>  &nbsp; &nbsp;筆 <br /><a href="search_advanced.php">前往進階搜尋</a>
  </div>
  <?php if ($totalRows_web_search > 0) { // Show if recordset not empty ?>
  <table width="555" border="0" cellspacing="0" cellpadding="0" background="images/back11_2.gif">
    <tr>
      <td width="25" align="left"><img src="images/board14.gif" /></td>
      <td width="93" align="center" valign="middle" background="images/board04.gif">商品圖</td>
      <td width="126" align="left" valign="middle" background="images/board04.gif">商品名稱</td>
      <td width="219" align="left" valign="middle" background="images/board04.gif">商品簡介</td>
      <td width="82" align="center" valign="middle" background="images/board04.gif">單價</td>
      <td width="10" align="right"><img src="images/board05.gif" width="10" height="28" /></td>
      </tr>
  </table>
    <table width="555" border="0" cellspacing="0" cellpadding="5">
      <?php do { ?>
        <tr class="font_black">
          <td width="14" align="center" class="board_add3"><? echo $i++;?></td>
          <td width="84" align="center" class="board_add3"><a href="products_detial.php?p_id=<?php echo $row_web_search['p_id']; ?>"><img src="images/shop/thum/<?php echo $row_web_search['p_pic']; ?>" width="57" border="0" /></a></td>
          <td width="116" align="left" class="board_add3"><?php echo $row_web_search['p_name']; ?></td>
          <td width="199" align="left" valign="middle" class="board_add3">
                  <?php
     //去除HTML標籤,先找到關鍵字第一次出現位置,並將字元位置儲存在自訂變數$start_place中
     $start_place=mb_strrpos(strip_tags($row_web_search['p_content']),$_GET['keyword'],"UTF-8");
     //希望關鍵字出現在商品簡介中央位置,所以起始字元位置-50(因為指定截取100個字元)
     $start_place=$start_place-50;
     //去除p_content欄位中,商品介紹文案的HTML及PHP語法標籤後,指定截取出100個字元後,儲存給變數$p_content
     $p_content=mb_substr(strip_tags($row_web_search['p_content']),$start_place,100,"UTF-8");
     //改用eregi_replace函數為搜尋結果中的關鍵字內容,替換文字樣式效果
     $p_content=eregi_replace($_GET['keyword'],"<font color='#ff0000' style='background:#ffff00'>".$_GET['keyword']."</font>",$p_content);
     //輸出最後效果
     echo $p_content;
?>....</td>
          <td width="92" align="center" class="board_add3"><?php echo $row_web_search['p_price']; ?></td>
        </tr>
        <?php  } while ($row_web_search = mysql_fetch_assoc($web_search)); ?>
    </table>
    <table width="555" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="left" valign="bottom">&nbsp;
          <table border="0">
            <tr>
              <td><?php if ($pageNum_web_search > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_web_search=%d%s", $currentPage, 0, $queryString_web_search); ?>">第一頁</a>
                  <?php } // Show if not first page ?></td>
              <td><?php if ($pageNum_web_search > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_web_search=%d%s", $currentPage, max(0, $pageNum_web_search - 1), $queryString_web_search); ?>">上一頁</a>
                  <?php } // Show if not first page ?></td>
              <td><?php if ($pageNum_web_search < $totalPages_web_search) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_web_search=%d%s", $currentPage, min($totalPages_web_search, $pageNum_web_search + 1), $queryString_web_search); ?>">下一頁</a>
                  <?php } // Show if not last page ?></td>
              <td><?php if ($pageNum_web_search < $totalPages_web_search) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_web_search=%d%s", $currentPage, $totalPages_web_search, $queryString_web_search); ?>">最後一頁</a>
                  <?php } // Show if not last page ?></td>
            </tr>
          </table></td>
        <td align="right" valign="bottom">&nbsp;
          記錄 <?php echo ($startRow_web_search + 1) ?> 到 <?php echo min($startRow_web_search + $maxRows_web_search, $totalRows_web_search) ?> 共 <?php echo $totalRows_web_search ?></td>
      </tr>
    </table>
    <?php } // Show if recordset not empty ?>
  </div>
  <div id="main4"></div>
</div>
<?php include("footer.php"); ?>
</body>
</html>
<?php
mysql_free_result($web_search);
?>
發表於 2011-4-22 19:36:56 | 顯示全部樓層
1# selinavyz

同學
你沒頭沒尾的貼上這一串語法
也沒說你做的動作是甚麼
怎麼幫你解決?
你這個語法是leftzone.php頁面的內容
裡面有登入、會員專區、觀看購物車、線上客服、訂閱電子報
你是做哪個部分出錯?
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



小黑屋|Archiver|手機版|聯成電腦技術論壇  

GMT+8, 2019-10-14 16:28

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表