You cannot use assign-op statements with overloaded objects or line offsets

I have this piece of code and it gives me an error in the header.

I have a counter $kfrom 1 to 5 for each table.

$myarray consists of at least 3 to 4 names.

The error occurs on the line with ... $qu .=

What I have tried so far: changed the variable variablename $ito $v{$i}in line $qu .=.

So, is it possible to repeat the request? So what is WHEREthere so much ANDthat the array counter is equal?

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++;
}
+5
source share
1 answer

It seems you misunderstood some basic PHP syntax.

As indicated in the manual :

string string, array, $str[42]. string array . substr() substr_replace() 1 .

: string , , $str{42}, .

( , for) , .

-, , PHP-; , MySQL. , PHP normalized. , description, Name, PHP, , , descriptionNames, 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_*. , . PDO , 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/>";
}
+6

All Articles