drf65218 2014-03-24 18:18
浏览 31
已采纳

显示存储在浏览器目录中的图像

This seems like such a simple thing to do but for some reason, I can't get this to work.

I have a database with vehicle data stored in it. (Used Cars (I'm developing a car dealership website)).

I successfully display results from the database without images.

The images for each record aren't stored in the database, instead they're dumped on the server in a directory and those images are only referenced in the database.

If I echo the image name out it works fine, and if I echo the actual image out, the path is correct if you look at the image info. But in the info it states that the image is of text. i don't know how to change this.

Please find some of the code below.

    <?php

        $dbName = "F:/Domains/autodeal/autodeal.co.za/wwwroot/newsite/db/savvyautoweb.mdb";

        // Throws an error if the database cannot be found
        if (!file_exists($dbName)) {
            die("Could not find database file.");
        }

        // Connects to the database
        // Assumes there is no username or password
        $conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$dbName", '', '');

        //this is selecting individual records
        $selected_id = intval($_GET['Id']);

        //this is the query
        $sql = "SELECT Id, Make, Model, Year, Price, SpecialPrice, Branch, StockNO, MainPic FROM Vehicle WHERE Id = $selected_id";

        // Runs the query above in the table
        $rs = odbc_exec($conn, $sql);

        $id = odbc_result($rs, Id);
        $make = odbc_result($rs, Make);
        $model = odbc_result($rs, Model);
        $mainPic = odbc_result($rs, MainPic);

        //this is a failsafe for when there are no images for a specific record
        $no_image = "<a href='db/Nopic.gif' data-lightbox='nopic' title='No Image Available'><img src='db/Nopic.gif' /></a>";

        //This successfully displays the name of the image referenced in the database
        $main_pic = "<img src='db/vehicleImages/'" .$mainPic. "/>";

        //this is supposed to display the actual
        echo $main_pic . "<br />";

        echo $no_image;


        odbc_free_result($rs);
        odbc_close($conn);

        // This message is displayed if the query has an error in it
        if (!$rs) {
            exit("There is an error in the SQL!");
        }

    ?>

Any help in the regard would be greatly appreciated.

Thank you. :)

  • 写回答

2条回答 默认 最新

  • dony39517 2014-03-24 18:21
    关注

    you should use quotations around the attributes of html objects (it looks like you might be breaking things via your method):

    yours:

    <a href=db/Nopic.gif data-lightbox=nopic title=No Image Available><img src=db/Nopic.gif /></a>
    

    correct:

    <a href='db/Nopic.gif' data-lightbox='nopic' title='No Image Available'><img src='db/Nopic.gif' /></a>
    

    whether or not this fixes your problem will be determined by what you come back with :p

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线边框
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题