stuck. code doesnt work..?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

stuck. code doesnt work..?

Post by phice »

http://onlygeeks.com/Personal/erm/functions.styles.phps

With my code above, it shows all of the html and what not, but I can't seem to get the $setting variable to work inside the function.

Thanks.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Try this.

Code: Select all

<?php
error_reporting(E_ALL);
mysql_connect('localhost', 'user', 'pass');
mysql_select_db('blastmb') or die(mysql_error());

$sql = "SELECT name, value FROM bmb_settings";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_object($result)){
  $setting[$row->name] = $row->value;
}

function topdef() {
  global $setting;
  echo <<<EOT
    <html>
    <head>
    <title>{$setting['site_title']}</title>
    <base href="{$setting['site_url']}">
    <script type="text/javascript" src="scripts/global.js"></script>
    <link rel="stylesheet" href="templates/default/styles/default.css" type="text/css">
    </head>
    <body>
    <center>
EOT;
}

function botdef() {
  $date = date('Y');
  echo <<<EOT
  <font style="cursor: default;">2003-{$date} &copy; Blast! Message Boards<br />Brought to you by DevBlast.com</font>
  </center>
  </body>
  </html>
EOT;
}

topdef();
botdef();

?>
You were basically missing, global $setting; inside your function.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Couldn't see any code - just a resume page.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

The problem was fixed. I took it offline.
Image Image
Post Reply