【问题标题】:php mysql fetch and display imagephp mysql 获取并显示图像
【发布时间】:2013-09-11 20:36:00
【问题描述】:

尝试访问数据库并显示位于电影表中的 imageurl 的内容似乎不起作用。有什么建议吗?

<?php
//connect to DB
$db = mysqli_connect("localhost", "awalke32", "21195453", "awalke32");
if (mysqli_connect_errno($db)) {
    print "Connect failed: " . mysqli_connect_error();
    exit();
} else {
    $myint = rand("1", "37"); //random number gererator

    $query = ("SELECT imageurl FROM movie WHERE movie_id=" . $myint); //think the error is in here but it works in Terminal secure shell
    $result = mysql_query($query);

    print "<table width=\"100%\"><tr>";
    print "<td align=\"center\">";
    print "<img src='images/" . $result . "' alt='Image'>"; //this is correct as it works in another page
    print "</td>";
    print "</td></tr></table>";
}
?>

【问题讨论】:

  • 这肯定行不通: print "php.net/manual/en/function.mysql-fetch-row.php
  • int rand ( int $min , int $max )

标签: php mysql imageurl


【解决方案1】:

换行: $myint = rand ("1", "37"); 到 $myint = rand (1, 37);

【讨论】:

  • 感谢您认为这些工作现在收到错误消息。 “无法为用户 'apache'@'localhost' 运行 queryAccess denied(使用密码:否)”
【解决方案2】:

在 rand 函数中以 int 形式发送参数

从结果中获取数据数组

$myint = rand (1, 37);

$query = ("SELECT imageurl FROM movie WHERE movie_id=".$myint);

$result = mysql_query($query);

if($row = msyql_fetch_array($result)) {
    $image = $row["imageurl"];

    print "<table width=\"100%\"><tr>";
    print "<td align=\"center\">";
    print "<img src='images/".$image."' alt='Image'>";
    //this is correct as it works in another page
    print "</td>";
    print "</td></tr></table>";
}

【讨论】:

    猜你喜欢
    • 2013-08-11
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-13
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多