纽布在这里。
问题:我期待两个(2)图像出现在h1中,由开关盒传送(并随机化)。一个是以标准方式提供的,但它会出现,但是另一个将通过var $ widget01传递的方式不会出现。
You Can See How the Code is Working here at my test website
我现在该功能正常运行,因为我已经测试了(h1中的第一个图像是通过函数ok传递的),但是当我尝试使用$ widget01 var传递它时,没有任何反应。
我正在试图弄清楚如何使用我的配置将内容传递到一个页面而不是另一个页面。为了做到这一点,我需要得到开关案例将它们传递到我的测试页面(然后我可以在该栏上将var设置为null以不提供它)。我很擅长如何不提供,但我无法提供,所以图像会像希望的那样出现。
以下代码
我的'config.php'中的代码: //config.php
include 'credentials.php'; //database credentials
//echo DB_USER;
//die;//exit before html is sent - just want to see connection works!
// ------ Error Handling ------ //
define('DEBUG',TRUE); #we want to see all errors
function myerror($myFile, $myLine, $errorMsg)
{
if(defined('DEBUG') && DEBUG)
{
echo "Error in file: <b>" . $myFile . "</b> on line: <b>" . $myLine . "</b><br />";
echo "Error Message: <b>" . $errorMsg . "</b><br />";
die();
}else{
echo "I'm sorry, we have encountered an error. Would you like to buy some socks?";
die();
}
}
define ('THIS_PAGE', basename($_SERVER['PHP_SELF']) ); //Constant is UPPERCASED, no dollar sign
//echo THIS_PAGE;
$nav1['index.php'] = "Home";
$nav1['about.php'] = "About";
$nav1['contact.php'] = "Contact";
$nav1['samples.php'] = "Samples";
$nav1['goodies.php'] = "Goodies";
$heroes = '';//used for randomizer - initialize var
$planets = '';//used for randomizer - initialize var
switch(THIS_PAGE)
{
//Set most likely scenario as the first to run
case 'index.php' :
$title = "Home" ;
$banner = "Home: Both random() & rotate()";
$widget01 = randomize($heroes);
$widget02 = rotate($planets);
break;
case 'about.php' :
$title = "About" ;
$banner = "About: Only Random()";
$widget01 = randomize($heroes);
//$widget02 = rotate($planets);
break;
case 'contact.php' :
$title = "Contact" ;
$banner = "Contact: Only Random()";
$widget01 = randomize($heroes);
//$widget02 = rotate($planets);
break;
case 'samples.php' :
$title = "Samples" ;
$banner = "Samples: Only Rotate()";
//$widget01 = randomize($heroes);
$widget02 = rotate($planets);
break;
case 'goodies.php' :
$title = "Goodies" ;
$banner = "Goodies: Only Rrotate()";
//$widget01 = randomize($heroes);
$widget02 = rotate($planets);
break;
case 'template.php' :
$title = "Template";
$banner = "Neither random() & rotate()";
//$widget01 = randomize($heroes);
//$widget02 = rotate($planets);
break;
default :
$title = "Our Cool Webstie";
$banner = "Default Banner";
$widget01 = randomize($heroes);
$widget02 = rotate($planets);
break;
}
Randomizer() function in 'Config.php':
function randomize ($arr)
{//randomize function is called in the right sidebar - an example of random (on page reload)
if(is_array($arr))
{//Generate random item from array and return it
return $arr[mt_rand(0, count($arr) - 1)];
}else{
return $arr;
}
}#end randomize()
'header.php'中的代码:
<h1 class="brand">
$heros[] = '<img src="img/heroes/coulson.png" />';
$heros[] = '<img src="img/heroes/fury.png" />';
$heros[] = '<img src="img/heroes/hulk.png" />';
$heros[] = '<img src="img/heroes/thor.png" />';
$heros[] = '<img src="img/heroes/black-widow.png" />';
$heros[] = '<img src="img/heroes/captain-america.png" />';
$heros[] = '<img src="img/heroes/machine.png" />';
$heros[] = '<img src="img/heroes/iron-man.png" />';
$heros[] = '<img src="img/heroes/loki.png" />';
$heros[] = '<img src="img/heroes/giant.png" />';
$heros[] = '<img src="img/heroes/hawkeye.png" />';
echo randomize($heros);//THis one appears
echo randomize($widget01); //this one doesn't
?>
<a href="index.html"><?=$banner?></a></h1>
You Can See How the Code is Working here at my test website
请注意我已经尝试谷歌答案并阅读堆栈溢出和其他地方的一些有趣的事情,但没有任何我能够理解的东西,以弄清楚我的问题是什么。我是一个新人,仍在努力成为一个爱好
答案 0 :(得分:0)
我发现了这个问题,就是这个阵列被命名为“英雄&#39;但是当我打电话给我时,我打电话给英雄&#39; sans&#39;。当我在这里输入代码进行审核时,我认为我的浏览器自动修正了它,所以好人们无法看到这个错误,或者我确定所有人都会抓住它。