下面的代碼工作正常,它從文件夾中隨機選擇一個圖像,並將其作爲背景分配給生成的Div。這工作。如果我再次使用此代碼,但使用它來簡單地放置隨機圖像的img-src,這也可以。但是,以與第一種相同的方式使用代碼會破壞網站。我究竟做錯了什麼?兩個幾乎完全相同的代碼片..一個可以工作,另一個不可以
<!-- BEGIN FEATURED 1 -->
<?php
try {
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
}
catch (PDOException $e) {
echo $e->getMessage();
echo 'Could not establish a connection to the database.';
}
$query = $conn->prepare('SELECT `articleid`,`title` FROM `news_articles` WHERE featured = 1 ORDER BY RAND() LIMIT 1');
$array = array(
'N'
);
$query->execute();
$results = $query->fetchAll(PDO::FETCH_COLUMN, 0);
foreach ($results as $row) {
}
$image = get_rand_img('images/featured_images/csgo/');
$title = $result['title'];
echo '<a href="index.php?viewarticle=1&articleid=' . $row . '">';?>
<div id="featured-image" style="height: 267px; width: 292px; background:url(/images/featured_images/csgo/<?php echo $image ?>)">
<?php
$result = $conn->prepare("SELECT `articleid`,`title`,`short_title` FROM `news_articles` WHERE articleid=$row");
$result->execute();
$rows = $result->fetch();
echo '<div class="featuredtitle1">';
echo $rows['short_title'];
echo '</div>';
echo '</div>';
echo '</a>';
?>
下面的代碼,會導致網站..(我曾評論它的那一刻,你可以看到)。
<!-- BEGIN FEATURED 2 (Disabled) -->
<?php
/*
try {
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
}
catch (PDOException $e) {
echo $e->getMessage();
echo 'Could not establish a connection to the database.';
}
$query = $conn->prepare('SELECT `articleid` FROM `news_articles` WHERE featured = 1 ORDER BY RAND() LIMIT 1');
$array = array(
'N'
);
$query->execute();
$results = $query->fetchAll(PDO::FETCH_COLUMN, 0);
foreach ($results as $row) {
}
$image = get_rand_img('images/featured_images/dota/');
$title = $result['title'];
echo '<a href="index.php?viewarticle=1&articleid=' . $row . '">';?>
<div id="featured-image2" style="height: 267px; width: 292px; background:url(/images/featured_images/dota/<?php echo $image ?>)">
<?php
$result = $conn->prepare("SELECT `articleid`,`title`,`short_title` FROM `news_articles` WHERE articleid=$row");
$result->execute();
$rows = $result->fetch();
echo '<div class="featuredtitle2">';
echo $rows['short_title'];
echo '</div>';
echo '</div>';
echo '</a>';
*/
?>
我不明白爲什麼第一段代碼很好,但是再次複製它會破壞它?
你得到什麼錯誤? –
嚴格的標準:只有變量應該通過引用傳遞給C:\ xampp \ htdocs \ index.php,行953 – MikeXero
,它是'$ ext = end(explode('。',$ file)); if($ ext =='gif'|| $ ext =='jpeg'|| $ ext =='jpg'|| $ ext =='png'|| $ ext =='GIF'|| $ ext = ='JPEG'|| $ ext =='JPG'|| $ ext =='PNG'){' – MikeXero