Function
Hej EksperterJeg er igang med at lave mit eget "lille" projekt.
Jeg er ved at prøve at få functions til at være en den af hjemmesiden.
Så jeg altid har et godt overblik.
Det er lige er problemet er når jeg kalder på den, kommer der ingen ting. melder bare fejl. Undefined variable: banner feks.
<?php require_once('database/database.php'); ?>
<?php
function hent_grundside($con){
/* Select et prepared statement */
if ($stmt = $con->prepare('SELECT `id`, `title`, `banner`, `copyright`, `tekst` FROM `tbl_grundside`')) {
/* Bind parametre */
$stmt->bind_param('i', $id);
/* Sæt værdier på parametrene */
$id = 1;
/* Eksekver forespørgslen */
$stmt->execute();
/* Bind resultatet */
$stmt->bind_result($id, $title, $banner, $copyright, $tekst);
/* Hent rækker og udskriv data */
while ($stmt->fetch()) {
;}}}
?>
Her er den måde jeg prøver at stille det op på:
Min function:
<?php require_once('database/database.php'); ?>
<?php require_once('functions/grundside.php'); ?>
<?php
hent_grundside($con);
?>
<!doctype html>
<!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
<!--[if IE 7]> <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]> <html class="ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo $title; ?></title>
<link href="boilerplate.css" rel="stylesheet" type="text/css">
<link href="_style/_style.css" rel="stylesheet" type="text/css">
<!--
To learn more about the conditional comments around the html tags at the top of the file:
paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
Do the following if you're using your customized build of modernizr (http://www.modernizr.com/):
* insert the link to your js here
* remove the link below to the html5shiv
* add the "no-js" class to the html tags at the top
* you can also remove the link to respond.min.js if you included the MQ Polyfill in your modernizr build
-->
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="respond.min.js"></script>
</head>
<body>
<div class="gridContainer clearfix">
<div id="Banner"><?php echo $banner; ?>
<div id="Body">Body</div>
<div id="Tekst"><?php echo $tekst; ?></div>
<div id="Copyright"><?php echo $copyright; ?></div>
</div>
</div>
</body>
</html>
Med venlig hilsen
Morten
