3.grosz Posted March 16, 2009 Share Posted March 16, 2009 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 More sharing options...
thebadbad Posted March 16, 2009 Share Posted March 16, 2009 You should then include about.php at the top of site1.php: site1.php <?php include('about.php'); ?> <!DOCTYPE html ... Link to comment https://forums.phpfreaks.com/topic/149626-hide-and-seek-with-php/#findComment-785701 Share on other sites More sharing options...
3.grosz Posted March 16, 2009 Author Share Posted March 16, 2009 It doesn't work. <?php include('about.php');?> If I change file for 'a.txt', it works, but there's no sense. There must be another way. Link to comment https://forums.phpfreaks.com/topic/149626-hide-and-seek-with-php/#findComment-785732 Share on other sites More sharing options...
pkSML Posted March 16, 2009 Share Posted March 16, 2009 <?php $data["History"] = "long value 1"; $data["Contact"] = " value text 2"; $data["Offer"] = "long value 3"; $data["Clients"] = "long value 4"; ?> What happens when this code is saved to about.php and included on your main page? Link to comment https://forums.phpfreaks.com/topic/149626-hide-and-seek-with-php/#findComment-785736 Share on other sites More sharing options...
thebadbad Posted March 16, 2009 Share Posted March 16, 2009 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> Link to comment https://forums.phpfreaks.com/topic/149626-hide-and-seek-with-php/#findComment-785741 Share on other sites More sharing options...
Mchl Posted March 16, 2009 Share Posted March 16, 2009 change include to require and see what it says. Link to comment https://forums.phpfreaks.com/topic/149626-hide-and-seek-with-php/#findComment-785746 Share on other sites More sharing options...
3.grosz Posted March 16, 2009 Author Share Posted March 16, 2009 And now it works. Thanks Link to comment https://forums.phpfreaks.com/topic/149626-hide-and-seek-with-php/#findComment-785751 Share on other sites More sharing options...
3.grosz Posted March 16, 2009 Author Share Posted March 16, 2009 and this. Link to comment https://forums.phpfreaks.com/topic/149626-hide-and-seek-with-php/#findComment-785753 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.