php mysql获取并显示图像

时间:2013-09-08 02:42:14

标签: php mysql imageurl

尝试访问数据库并显示位于影片表中的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>";
}
?>

2 个答案:

答案 0 :(得分:1)

更改行: $ myint = rand(“1”,“37”); 至 $ myint = rand(1,37);

答案 1 :(得分:0)

参数在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>";
}