jquery simplecart php variables


jquery simplecart php variables

我有困难的onclick jquery在我的php代码,我如何得到一个php变量,使名称=变量和价格=变量?

    <?php
    $result = mysqli_query($db,"SELECT * FROM table");
    while($row = mysqli_fetch_array($result)) {
      echo '<ul>';
      echo '<li>' . $row['selection'] . '<div style="float:right;"><a href="#" onclick="simpleCart.add('name='. $row['selection'] . ','price='. $row['price'] .');return false;
     "> '. $row['price'] . '</a></div></li>';
      echo '</ul>';
      }
      ?>

我如何绕过这个?由于

用这行修改你的代码…

echo '<div style="float:right;"><a href="#"
onclick="simpleCart.add(name='.$row['selection'].',price='.$row['price'].')"
</a></div>';

不熟悉simplecart,但是您肯定需要正确转义您的引号。

<?php
    $result = mysqli_query($db,    "SELECT * FROM table");
    while($row = mysqli_fetch_array($result)) { 
        echo '<ul>'; 
        echo '<li>' . $row['selection'] . '<div style="float:right;"><a href="#" onclick="simpleCart.add(''name='''. $row['selection'] . ',''price='''. $row['price'] . ');return false; "> '. $row['price'] . '</a></div></li>'; echo '</ul>'; }
?>