PHP在MYSQL数据上设置变量

时间:2017-02-06 12:54:00

标签: php mysql

这是我的PHP代码,我目前正在使用。

<?php
$servername = "localhost";
$username = "user";
$password = "123";
$dbname = "db";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
} 
$sql = "SELECT fontsize FROM fb_test WHERE id = 15 ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo $row["fontsize"];
    }
} else {
    echo "0 results";
}
$conn->close();
?>

<?php $servername = "localhost"; $username = "user"; $password = "123"; $dbname = "db"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT fontsize FROM fb_test WHERE id = 15 "; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo $row["fontsize"]; } } else { echo "0 results"; } $conn->close(); ?> 我想做这样的事

$var = echo $row["fontsize"];
....
....
imagettftext($this->fond,$var,0,200,400,$textcolor,$font,$item_text);
有人可以帮我这样做吗?如果有人知道帮助我,我试过everthing但不工作

1 个答案:

答案 0 :(得分:1)

$ var = $ row [“fontsize”];

imagettftext($这 - &GT;喜欢,$变种,0200400,$文本颜色,字体$,$ ITEM_TEXT);

删除回声并使用。

只有在屏幕上打印值时,

回显才有用。