English 中文(简体)
无法通过站点阵列从数据库中展示图像
原标题:unable to display images from database via php array
  • 时间:2011-11-05 19:41:44
  •  标签:
  • php

学习!

我有一张名为“图像”的表格,该表储存了用户将上载的图像途径。 我正在把图像路径从数据库中拉开到PHP阵列,然后把路把图像展示在屏幕上作为清单项目。 然而,当我上页时,没有显示任何东西。

数据库连接代码:

include( Database.php );

class Images extends Database{

private $_images = array();

public function __construct(){

  $conn = $this->create_connection( read );     
  $sql = "SELECT image_path FROM  items  WHERE catagory= tshirt ";      
  $result = $conn->query($sql)or die(mysql_error());        
  while($paths = mysql_fetch_array($result)) {      
    $this->_images[] = $paths[ catagory ];      
  }         
}

public function getItems() {        

  return $this->_images;   
}

意见守则:

<ul>
<?php
require ( ../model/Images.php );
$imageArray = array();
$images = new Images();
$imageArray[] = $images->getItems();
foreach($ImageArray as $value){
        echo  <li><img src=" .$value. "></li> ;
}   
?>
</ul>

我用Sandkmyadmin执行询问,而后者的质询是正确的。 此外,我还通过人工添加图像途径,以测试通过阵列进行的循环,模拟数据库数据。

private $_images = array( ./images/tshirt1.jpg , etc, etc);

so I know the foreach loop and query work. The create_connection function I have used before, connecting to the same database without any issues, I am a bit stumped, but I think it may be connected to the mysql_fetch_array section?

我采用正确做法吗? 或是否有更好的办法解决这一问题?

希望的人能够把我引向正确的方向!

增 编

最佳回答

更改<代码>$imageArray[] = images->getItems(); to $imageArray = images->getItems();,以数字精确度建议的变化为准

EDIT:

$imageArray = $images->getItems();
var_dump( $imageArray );
foreach($imageArray as $value) {
        var_dump( $value );
        echo  <li><img src=" .$value. "></li> ;
}

你们会发现哪里数据松散。 我希望这与非行的错误形象道路无关。

EDIT:

始终显示......贵国空白页的核对来源,看看显示什么,如果被丢弃的变量是空洞的,那么.var_dump($images );应当显示在物体上坐的是什么,如果仍然有财产-images是空阵,则在建筑商身上存在问题,则可能要尝试<条码>。

问题回答

除你外,别看一看ok;一等杂草;二等杂草,但从我sql、图像_path中挑选的 was类。

while($paths = mysql_fetch_array($result)) {        
    //$this->_images[] = $paths[ catagory ];
    $this->_images[] = $paths[ image_path ];      
}  




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签