duanqiongniu1469 2017-05-02 20:13 采纳率: 100%
浏览 32

打印查询问题 - MySQL,PHP,HTML -

I had a very random problem in an IIS class, it has stumped my tutor so here I am and I'll try my best to explain it well!

I'm running Xampp with Apache and MySQL, I run the query I want and get the expected output to a table, but I have a problem with the outputting of pictures. I have the right file type, extention and path selected, because I can get pictures to show up, but as long as at least one picture in the query result has the extension removed, and this picture will not load.

Database

enter image description here

Website

enter image description here

If I have each query result with the correct name and extension, which is the same as when it shows up, none of them show up at all!

PHP:

<?php 

// set server access variables 
  include 'db2.inc';

// open connection 
$connection = mysql_connect($hostname, $username, $password) or die ("Unable             to connect!"); 

// select database 
mysql_select_db($databaseName) or die ("Unable to select database!"); 

// create query 
//$query = "SELECT * FROM products"; 
$query = "SELECT * FROM products WHERE CategoryName = 'Surfboards'"; 
//Check initial letter
//if (!$initialLetter=="")
//{ 
//  $query = $query." Where country like  '$initialLetter%' ";
//}

// execute query 
$result = mysql_query($query) or die ("Error in query: $query.     ".mysql_error()); 

// see if any rows were returned 
if (mysql_num_rows($result) > 0) { 
// yes 
// print them one after another 
echo "<table cellpadding=20 border=1>"; 
while($row = mysql_fetch_assoc($result)) { 
    echo "<tr>"; 
    echo "<td>".$row['ProductID']."</td>"; 
    echo "<td>".$row['Name']."</td>"; 
    echo "<td>".$row['Description']."</td>"; 
    echo "<td>".$row['Brand']."</td>"; 
    echo "<td>".$row['Model']."</td>"; 
    echo "<td>".$row['BoardLength']."</td>"; 
    echo "<td>".$row['BoardType']."</td>"; 
    echo "<td>".$row['Colour']."</td>"; 
    echo "<td>"."<img src=images/".$row['Image']."> </td>";
    echo "<td>".$row['UnitPrice']."</td>"; 
    echo "<td>".$row['CategoryName']."</td>"; 
    echo "</tr>"; 
} 
echo "</table>"; 
} 
else { 
// no 
// print status message 
echo "No rows found!"; 
} 

// free result set memory 
mysql_free_result($result); 

// close connection 
mysql_close($connection); 

?> 

Any help or direction would be greatly appreciated!

Thanks

Will

  • 写回答

1条回答 默认 最新

  • douyoupingji7238 2017-05-02 20:27
    关注

    On this line:

    echo "<td>"."<img src=images/".$row['Image']."> </td>";
    

    Your image src is not enclosed in quotes. If this is a direct copy/paste of your code then that is definitely a problem, but may not be the only one.

    As other people have said, look at pdo, or mysqli. The mysql_ functions you are using are deprecated for multiple reasons.

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划