-1

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

2 回答 2

1

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

于 2013-09-08T02:44:42.410 回答
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>";
}
于 2013-09-08T03:59:42.050 回答