English 中文(简体)
无法使用有超载对象或字符串偏移的指定操作操作操作操作器
原标题:Cannot use assign-op operators with overloaded objects nor string offsets

我有这部分的代码 它给了我标题上的错误

每个表格的计数$k 为1至5。

$myarray由至少3至4个地名组成。

错误发生于 <% code> $qu. {{{/code} / nuger>...

我迄今尝试过的:将变量名 $i 改为 $v{$i_%/code> 。 $qu./code> 。

那么,有没有可能复制查询? 因此, 它在 < code> where 条款中拥有与数组数数一样多的 < code > 和 条款?

while ($k<=5) {
  $queryname = "SELECT Name FROM description";
  $qname = mysql_query($queryname,$link);

  while ($reihe = mysql_fetch_object($qname)) {
    {
      $unse = unserialize($reihe->Name);
      {
        foreach ($unse as $j=>$h)
          foreach ($h as $m) {
            $myarray = preg_split( / |s| / ,$m);
            {
              echo "<br>";
              $array_empty = $myarray;
              $empty_elements = array("");
              $myarray = array_diff($array_empty,$empty_elements);
              var_dump($myarray);
              for ($i=1; $i<=count($myarray); $i++) {
                $v{$i} = $myarray[$i];
                echo $v{$i};
                $esc{$i} = strtolower(mysql_escape_string($v{$i}));
                echo "<br>" . $esc{$i} . "<br>";
                $qu = "SELECT * FROM `table ID=$k` WHERE";
                $qu{$i} .= "AND `table ID=$k`.`name` LIKE  %$esc{$i}% ";
              }
            }
          }
        {
          $test_a = mysql_query($qu,$link) or die (mysql_error());
          echo "<br>";
          var_dump($test_a);
          for ($x=0; $x<mysql_num_rows($test_a); $x++) {
            $row = mysql_result($test_a,$x, data1 );
            $namee = mysql_result($test_a,$x, data2 );
            echo  data1  . $row .  <br> ;
            echo  data2  . $namee .  <br> ;
          }
        }
      }
    }
  }
  $k++;
}
问题回答

你似乎误解了PHP基本语法。

http://www.php.net/manual/en/languages.types.string.php#languages.types.string.substr" rel=“noreferrer”>手册。

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

注: String 也可用牙套访问,如$str{42/code/em>中为同一目的。

因此,你在整个代码中使用卷盖(定义 < /code> 控制结构 < code> 范围的人除外)完全错误,不能达到你的意图。

其次,从您的代码看,您似乎正在将关联数据存储在序列式 PHP 对象中; 这不利于使用像 MySQL 这样的 RDBMS 的很多好处。 除非您有令人信服的理由不这样做, 否则您可能应该将您的 PHP 对象存储在 < a href=" http://en.wikipedia. org/wiki/ Database_irmalization" rel= “ noreferrr” > 身份化 表格中。 例如, 而不是每个有 < code> description 记录的 < code > 字段, 包括一个包含有未定义的字符串的序列式的 PHP 对象, 只要将每个这样的名称存储在新的 < code> descriptionName 表格中, 引用了 < code> description 表中的有关记录:

CREATE TABLE descriptionNames (
  descriptionID INT NOT NULL,
  name VARCHAR(50),
  PRIMARY KEY (descriptionId, name),
  FOREIGN KEY (descriptionId) REFERENCES description (descriptionId)
);

似乎还有五张相同的表格,名称为 Table ID=1 , table ID=2 等。 如果是这样的话,您应该 可能 将您的五张表格合并为一张,并用一列(如果需要的话)标明记录来源于哪个表格;我还建议修改表格名称,以避免使用特殊字符,如白色空间和,因为如果您忘记正确引用这些字符,它们只会在路上造成更多麻烦和混乱。

ALTER TABLE `Table ID=1`
  RENAME TO CombiTable,
  ADD COLUMN FromTableID TINYINT NOT NULL;

UPDATE CombiTable SET FromTableID = 1;

INSERT INTO CombiTable
  SELECT *, 2 FROM `Table ID=2` UNION ALL
  SELECT *, 3 FROM `Table ID=3` UNION ALL
  SELECT *, 4 FROM `Table ID=4` UNION ALL
  SELECT *, 5 FROM `Table ID=5`;

SELECT * FROM CombiTable;  -- check everything is okay

DROP TABLE `Table ID=2`, `Table ID=3`, `Table ID=4`, `Table ID=5`;

无论如何,你不应该使用古老的mysql/code> 函数。 它们不再维持, 社区已经开始 < a href=" http://news.php.net/pp. intermans/ 53799" rel = “ noreferr” > depectation process 。 相反, 你应该了解 < a href=" http://en.wikipedia.org/wiki/prepared_state" rel="noreferr" 的预设声明 , 并且使用 < a href=" rel=" http://php.net/pdo" rel=" noreferr > PDO 抽象生物层或其它改良的 < a href=" http://php. net/mysqli" referr> > MySQLi 扩展。

如果您需要维持您现有的数据结构, 与 PDO 合作, 您可以做一些类似的事情 :

$dbh = new PDO("mysql:dbname=$dbname;charset=utf8", $user, $password);

$qry = $dbh->query("SELECT Name FROM description");
$myarray = array();
while ($reihe = $dbh->fetchColumn())
  foreach (unserialize($reihe) as $h)
    foreach ($h as $m)
      array_merge($myarray, preg_split("/s+/", $m, -1, PREG_SPLIT_NO_EMPTY));

for ($k = 1; $k <= 5; $k++) {
  $qry = $dbh->prepare("SELECT * FROM `table ID=$k` WHERE " . implode(" OR ",
    array_pad(array(), count($myarray), "name LIKE CONCAT( % , ?,  % )")
  ));

  $qry->execute($myarray);
  while($row = $qry->fetch()) {
    echo "data1:$row[data1]<br/>";
    echo "data2:$row[data2]<br/>";
  }
}

然而,利用我提议的新数据结构,你只需要:

$dbh = new PDO("mysql:dbname=$dbname;charset=utf8", $user, $password);

$qry = $dbh->query("
  SELECT   *
  FROM     CombiTable JOIN descriptionNames USING (name)
  WHERE    FromTableID BETWEEN 1 AND 5   -- in case you have others?
  ORDER BY FromTableID
");

while ($row = $qry->fetch()) {
  echo "data1:$row[data1]<br/>";
  echo "data2:$row[data2]<br/>";
}




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...