回应使用MySQL从数据库中提取数据的按钮

I have an issue with either quotation marks or syntax, I'm not entirely sure.

Here's the code:

<div class="pagination btn-group" id="items">
                    <? $sql = "SELECT itemname FROM items ORDER BY itemname ASC";
                    $result = mysql_query($sql);

                    $id = $row['id'];
                    $itemname = $row['itemname'];
                    $price = $row['price'];

                    while ($row = mysql_fetch_array($result))
                    {
                        echo "<button class='btn btn-medium highlight-color-0' id=$id itemname=$itemname price=$price><div class='btn-image gears'></div><span class='btn-text'>$itemname</span>";
                    }

                    echo "</button>"; ?>
                </div>

I then call to this in jQuery using this code:

$('.pagination btn-group').click(function()
                    {
                        id = $(this).attr('id');
                        name = $(this).attr('itemname');
                        price = $(this).attr('price');
                    });

However, I seem to be getting undefined results? Any help would be appreciated

you should put the below lines inside while loop

$id = $row['id'];
$itemname = $row['itemname'];
$price = $row['price'];

should be like

while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$itemname = $row['itemname'];
$price = $row['price'];

echo "<button class='btn btn-medium highlight-color-0' id=$id itemname=$itemname price=$price><div class='btn-image gears'></div><span class='btn-text'>$itemname</span>";
}