MySQL查询与jQuery addClass没有显示[重复]

This question already has an answer here:

One of the first database outputs and i'm pretty much stuck. I want to add different classes to an array of information. The array has categories and that will be the leading value to add the class to. The code i'm using so far is:

<?php

    $sql = "SELECT name,title,content,date,category FROM pinboard";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {

        // output data of each row
        while($row = $result->fetch_assoc()) {

            echo "<article class='pin'><h2 class='pintitle'>".$row["title"]."</h2><p class='pincontent'>".$row["content"]."</p><div class='pininfo'><p class='pinname'>".$row["name"]."</p><p class='pindate'>".$row["date"]."</p></div></article>";

            if($row['category'] = 2){

                $('.pin').addClass("pin-message");
            }
            else if($row['category'] = 1){
                $('.pin').addClass("pin-photo");
            }
            else if($row['category'] = 3){
                $('.pin').addClass("pin-event");
            }
        }

    } else {
        echo "0 results";
    }
?>

The if($row[category'] = 2){ line gives this result when it's displayed:

Parse error: syntax error, unexpected '(', expecting variable (T_VARIABLE) or '$' in C:\wamp\www....\index.php on line ..

I'm probably not identifying the problem correctly but I'm hoping you guys could help me further.

</div>

You are mixing php with javascript.
And you are making it far more complicated than it needs to be.

Assuming everything above is fine (db-connection, query, ...), this shall be one better way to achieve what you want:

<?php

$sql = "SELECT name,title,content,date,category FROM pinboard";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

  while($row = $result->fetch_assoc()) {
    // define css-classes in php already
    $classes="pin";
    switch ($row['category']) {
        case 1:
            $classes .= " pin-photo";
            break;
        case 2:
            $classes .= " pin-message";
            break;
       //...and so on
    }
    // and then simply display them in first place
    echo "<article class='".$classes."'><h2 class='pintitle'>".$row["title"]."</h2><p class='pincontent'>".$row["content"]."</p><div class='pininfo'><p class='pinname'>".$row["name"]."</p><p class='pindate'>".$row["date"]."</p></div></article>";
    // no need for any js-dom-manipulation afterwards
  }
} else {
     echo "0 results";
}
?>

Appendum
you had two major misstakes:
1. trying to call js-functions from php
2. wrong comparison: if($x=1) does NOT compare, but assign 1 to $x. Thus if will always be true. Correct is $x===1 or $x==1 (that difference is another topic...)