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 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入