显示db info中的图像

时间:2016-02-03 18:50:14

标签: php html

首先,我是编码的业余爱好者,到目前为止我所做的一切都是追踪和错误。我正在尝试生成一个将信息导出到网页的表。到目前为止一切正常,除了我无法弄清楚如何显示图像。它只显示图像存储位置的http。我还希望此图像显示为缩略图,单击时可以在灯箱全尺寸中打开。 这将是表中的30行或更多行。

我目前的编码是:

<?php
echo "<table style='border: solid 1px black;'>";
echo "<th>Team Name</th><th>Team Captian</th><th>Total Damage</th><th>Best 1</th><th>Best 2</th><th>Best 3</th><th>Best 4</th><th>Best 5</th></tr>";

class TableRows extends RecursiveIteratorIterator { 
    function __construct($it) { 
        parent::__construct($it, self::LEAVES_ONLY); 
    }

    function current() {
        return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
    }

    function beginChildren() { 
        echo "<tr>"; 
    } 

    function endChildren() { 
        echo "</tr>" . "\n";
    } 
} 

$servername = "localhost";
$username = "user2_pvedama";
$password = "*********";
$dbname = "user2_pvedamage";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $stmt = $conn->prepare("SELECT username, fullname, damage, FILEUPLOAD1, FILEUPLOAD2, FILEUPLOAD3, FILEUPLOAD4, FILEUPLOAD5  FROM tdamage"); 
    $stmt->execute();

    // set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); 
    foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) { 
        echo $v;
    }
}
catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>

非常感谢任何帮助。我搜索过该网站,但没有发现任何我可以使用的东西(据我所知)

所以更改了这部分,但我仍然遇到错误?

$a = "FILEUPLOAD1";
$b = "FILEUPLOAD2";
$c = "FILEUPLOAD3";
$d = "FILEUPLOAD4";
$e = "FILEUPLOAD5";

$stmt = $conn->prepare("SELECT username, fullname, damage, echo '<img src="' . $a . '">';, echo '<img src="' . $b . '">';, echo '<img src="' . $c . '">';, echo '<img src="' . $d . '">';, echo '<img src="' . $e . '">';  FROM tdamage"); 
$stmt->execute();

更新至:

    $stmt = $conn->prepare("SELECT username, fullname, damage, FILEUPLOAD1, FILEUPLOAD2, FILEUPLOAD3, FILEUPLOAD4, FILEUPLOAD5  FROM tdamage"); 
    $stmt->execute();

    // set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); 
    foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) { 
        echo $v; if (strstr($k, 'FILEUPLOAD1')) { echo '<img src="' . $v . '">'; }
    }
}
catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>

当前更新的代码:

<?php
echo "<table style='border: solid 1px black;'>";
echo "<th>Team Name</th><th>Team Captian</th><th>Total Damage</th><th>Best 1</th><th>Best 2</th><th>Best 3</th><th>Best 4</th><th>Best 5</th></tr>";

class TableRows extends RecursiveIteratorIterator { 
    function __construct($it) { 
        parent::__construct($it, self::LEAVES_ONLY); 
    }

    function current() {
        return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
    }

    function beginChildren() { 
        echo "<tr>"; 
    } 

    function endChildren() { 
        echo "</tr>" . "\n";
    } 
} 

$servername = "localhost";
$username = "user2_pvedama";
$password = "*********";
$dbname = "user2_pvedamage";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);



    $stmt = $conn->prepare("SELECT username, fullname, damage, FILEUPLOAD1, FILEUPLOAD2, FILEUPLOAD3, FILEUPLOAD4, FILEUPLOAD5  FROM tdamage"); 
    $stmt->execute();

// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC); 
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) { 
    if (strstr($k, 'FILEUPLOAD')) { 
        echo '<img src="' . $v . '">'; 
    }
}
catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>

0 个答案:

没有答案