Jump to content

false74

New Members
  • Posts

    5
  • Joined

  • Last visited

false74's Achievements

Newbie

Newbie (1/5)

1

Reputation

  1. Actually. I'm just a dumbass. I can't spell for anything... Sorry for your time. $databse .... $database My mistake
  2. Even when I remove the function and do this: It still is undefined. <?php foreach($database->queryAllShowRows() as $row) { echo " <li> <a href='?show=" . $row['show_mediadir'] . "' class='show'>" . "<img src='" . $row['show_mediadir'] . "/mainthumb.jpg' />" . "<span>" . $row['show_title'] . "</span>" . "</a>" . "</li>"; } ?>
  3. showdb.php <?php class DBManager { var $showthumbfile; var $dblocation; var $db; var $mediaroot; var $showtable; var $epsiodetable; function CityBeatDBManager() { $showthumbrootdir = "thumbs/"; } function connectDB() { try { $db = new PDO('sqlite:' . $dblocation); } catch( PDOException $e ) { die('Error connecting to show database'); } } //QUERIES function queryAllShowRows() { return $db->query('SELECT * FROM shows ORDER BY show_id DESC')->fetchall(PDO::FETCH_ASSOC); } } ?> index.php <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test</title> <LINK REL=StyleSheet HREF="grey.css" TYPE="text/css" MEDIA=screen> </head> <body> <?php include_once("showdb.php"); $databse = new DBManager(); ?> <ul class="nav"> <li><a id="navbrowse" class="more" href="javascript:void(0);" onclick="toggleBrowse();">Our Programming</a></li> <li><a id="navabout" href="?page=about">About Us</a></li> </ul> </div> <div id="browse" class="close" tabindex=0 onclick="displayBrowse(false);" onblur="displayBrowse(false);"> <h1>Browse our programs</h1> <ul class="shownav"> <?php function listShows() { foreach($database->queryAllShowRows() as $row) { echo " <li> <a href='?show=" . $row['show_mediadir'] . "' class='show'>" . "<img src='" . $row['show_mediadir'] . "/mainthumb.jpg' />" . "<span>" . $row['show_title'] . "</span>" . "</a>" . "</li>"; } } listShows(); ?> </ul> </div> </div> <div id="wrapper"> <h1> <?php echo $databse->$dblocation; ?> </h1> </div> </body> </html> undefined variable when calling $database inside that foreach loop
  4. $thing is defined inside the first php code block, but cannot be accessed outside of that.
  5. Here is my problem/question: Say I have a class stored in a php file called 'myclass.php' and I have my main index php page 'index.php'. In that index.php page I include the 'myclass.php' file and create a variable as a new object of the class from myclass.php. However in the index page there are multiple php breaks <?php ?> <?php ?>, how can I use the variable that is of my class throughout the entire page? myclass.php: class MyClass { function MyClass() { ... } function foo() { ... } function bar() { ... } } index.php <html> <head> ... </head> <body> <?php include_once('myclass.php'); $thing = new MyClass(); ?> ... <?php $thing->foo(); ?> ... <?php $thing->bar(); ?> </body> </html> When trying to call $thing outside of the first php block I get an 'undefined variable' error. What is the scope of this variable, how can I have it shared amoungst all the php code blocks?
×
×
  • 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.