Jump to content

Hide-and-seek with PHP


3.grosz

Recommended Posts

What should I do, when I removed $data and I added $data to file about.php? How to find $data in this case?

 

Browser show this: Warning: Invalid argument supplied for foreach() in /home/(users name)/public_html/NOW/site1.php on line 41

 

Please help me. It's very important.

 

I added file site1.php without $data:

<?php
/*$data=array(
"History"=>"long value 1",
"Contact"=>"
value text 2",
"Offer"=>"long value 3",
"Clients"=>"long value 4");*/
?> 

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
<title>Simply site</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-2" />
<!-- <link rel="stylesheet" type="text/css" href="style.css" /> -->
<style type="text/css">
body { font-family: "Trebuchet MS"; font-size: 14px; padding: 0px; margin: 0px; }
.menu { margin-left: 150px; background-color: grey; width: 600px; }
.menu ul { margin: 0; padding: 0; }
.menu ul li { display: inline; }
.menu ul li a { padding: 54.4px; padding-bottom: 1px; padding-top: 1px; }
.menu a:visited { color: white; text-decoration: none; }
.menu a:hover { color: black; background-color: white; outline-color: red; }
.menu a:focus { color: lime; text-decoration: none; }
.middle { height: 150px; width: 600px; margin-bottom: 320px; margin-left: 150px; text-align: justify; line-height: 1.5; }
.middle h1 { padding-bottom: 2px; margin-bottom: 20px; border-bottom: 2px solid red; }
.middle p { text-indent: 1cm; }
.copyright p { margin-left: 150px; font-size: 10px; color: purpure }
.copyright a:active { color: green; }
</style>
</head>

<body>
<div class="menu">
<ul>
<li>
<?php
foreach ($data as $a=>$b) {
        echo "<a href=\"?subpage=".$a."\">$a</a>";
        }
?>
</li>
</ul>
</div>

<div class="middle">
<?php
if (!isset($_GET['subpage'])) {
    echo $_GET['subpage'];
} elseif (isset($_GET['subpage']) and (isset($data[$_GET['subpage']]))) {
    echo "<h1>".$_GET['subpage']."</h1>"."<p>".$data[$_GET['subpage']]."</p>";
}
/*if ((isset($_GET['subpage'])) and (!isset($data[$_GET['subpage']]))) {
$_GET['subpage'] = 'History'; }
echo "<h1>".$_GET['subpage']."</h1>"."<p>".$data[$_GET['subpage']]."</p>";*/
?>
<!-- <h1>Witamy Państwa na naszej stronie!</h1>
<p>Pragniemy zaproponować Państwu ofertę szkoleniowo-doradczą w zakresie projektowania i wdrażania systemów zarządzania.</p> -->
</div>
<div class="copyright">
<p>© 2009 Enterprise <a href="">„Name of enterprise”</a></p>
</div>
</body>
</html>

 

and I added file about.php with $data:

<?php
$data=array(
"History"=>"long value 1",
"Contact"=>"
value text 2",
"Offer"=>"long value 3",
"Clients"=>"long value 4");
?> 

Link to comment
https://forums.phpfreaks.com/topic/149626-hide-and-seek-with-php/
Share on other sites

Can't see how that would make any difference?

 

And how does it not work? It should look like this:

 

about.php

<?php
$data=array(
"History"=>"long value 1",
"Contact"=>"
value text 2",
"Offer"=>"long value 3",
"Clients"=>"long value 4");
?>

 

site1.php

<?php
include('about.php');
?><!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
<title>Simply site</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-2" />
<!-- <link rel="stylesheet" type="text/css" href="style.css" /> -->
<style type="text/css">
body { font-family: "Trebuchet MS"; font-size: 14px; padding: 0px; margin: 0px; }
.menu { margin-left: 150px; background-color: grey; width: 600px; }
.menu ul { margin: 0; padding: 0; }
.menu ul li { display: inline; }
.menu ul li a { padding: 54.4px; padding-bottom: 1px; padding-top: 1px; }
.menu a:visited { color: white; text-decoration: none; }
.menu a:hover { color: black; background-color: white; outline-color: red; }
.menu a:focus { color: lime; text-decoration: none; }
.middle { height: 150px; width: 600px; margin-bottom: 320px; margin-left: 150px; text-align: justify; line-height: 1.5; }
.middle h1 { padding-bottom: 2px; margin-bottom: 20px; border-bottom: 2px solid red; }
.middle p { text-indent: 1cm; }
.copyright p { margin-left: 150px; font-size: 10px; color: purpure }
.copyright a:active { color: green; }
</style>
</head>

<body>
<div class="menu">
<ul>
<li>
<?php
foreach ($data as $a=>$b) {
        echo "<a href=\"?subpage=".$a."\">$a</a>";
        }
?>
</li>
</ul>
</div>

<div class="middle">
<?php
if (!isset($_GET['subpage'])) {
    echo $_GET['subpage'];
} elseif (isset($_GET['subpage']) and (isset($data[$_GET['subpage']]))) {
    echo "<h1>".$_GET['subpage']."</h1>"."<p>".$data[$_GET['subpage']]."</p>";
}
/*if ((isset($_GET['subpage'])) and (!isset($data[$_GET['subpage']]))) {
$_GET['subpage'] = 'History'; }
echo "<h1>".$_GET['subpage']."</h1>"."<p>".$data[$_GET['subpage']]."</p>";*/
?>
<!-- <h1>Witamy Państwa na naszej stronie!</h1>
<p>Pragniemy zaproponować Państwu ofertę szkoleniowo-doradczą w zakresie projektowania i wdrażania systemów zarządzania.</p> -->
</div>
<div class="copyright">
<p>© 2009 Enterprise <a href="">„Name of enterprise”</a></p>
</div>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.