ready4god2513 Posted September 10, 2008 Share Posted September 10, 2008 I am pretty new to php. I am usually a CF developer, but I am really starting to seriously learn php and am liking it thus far. A project that I am working on has some code that I am refactoring. I am working on a class. The code looks right to me, but it stops my page request from happening (no error, but I just get a blank page). I haven't even called the object in my template. Here is the code. Can anyone help me with what I am doing wrong? class buildNavMenu { // Connect to the database db_connect(); function buildMenu () { // Call the findNavItems method. Loop over items. private $firstRow = findNavItems(); // Begin Loop private $itemCount = count($this->firstRow); for ($i = 0; i > $this->itemCount; i++) { // Get the sub-navigation private $nextRow = findNavItems($this->firstRow['id']); // Get the recordcount private $nextRowCount = count($this->nextRow); echo '<li id=" . $this->firstRow['displayName'] . ">'; echo '<a href=" . $this->firstRow['linkTo'] . "> . $this->firstRow['displayName'] . </a>'; if ($this->nextRowCount > 0) { echo '<ul class=" . $this->firstRow['displayname'] . ">'; // for ($i = 0; i > $this->nextRowCount; i++) { echo '<li><a href=" . $this->nextRow['linkTo'] ."> . $this->nextRow['displayName'] . </a></li>'; } echo '</ul>'; } echo '</li>'; } } private function findNavItems ($pageIdRel = 0) { // Run the query if ($pageIdRel == 0) { private $navData = mysql_query("SELECT id, displayName, link AS linkTo FROM Ot1GiZxOysW8_pages WHERE pageIdRel IS NULL isPublic = 1 AND startDate <= now() AND endDate >= now() AND draftOnly = 0 ORDER BY itemOrder ASC"); } else { private $navData = mysql_query("SELECT id, displayName, link AS linkTo FROM Ot1GiZxOysW8_pages WHERE pageIdRel = . $pageIdRel . isPublic = 1 AND startDate <= now() AND endDate >= now() AND draftOnly = 0 ORDER BY itemOrder ASC"); } // Save the results to an array private $navDataArray = mysql_fetch_array($this->navData); // Return the array to the caller return $this->navDataArray; } } Link to comment https://forums.phpfreaks.com/topic/123658-no-error-no-output/ Share on other sites More sharing options...
KevinM1 Posted September 10, 2008 Share Posted September 10, 2008 I am pretty new to php. I am usually a CF developer, but I am really starting to seriously learn php and am liking it thus far. A project that I am working on has some code that I am refactoring. I am working on a class. The code looks right to me, but it stops my page request from happening (no error, but I just get a blank page). I haven't even called the object in my template. Here is the code. Can anyone help me with what I am doing wrong? class buildNavMenu { // Connect to the database db_connect(); function buildMenu () { // Call the findNavItems method. Loop over items. private $firstRow = findNavItems(); // Begin Loop private $itemCount = count($this->firstRow); for ($i = 0; i > $this->itemCount; i++) { // Get the sub-navigation private $nextRow = findNavItems($this->firstRow['id']); // Get the recordcount private $nextRowCount = count($this->nextRow); echo '<li id=" . $this->firstRow['displayName'] . ">'; echo '<a href=" . $this->firstRow['linkTo'] . "> . $this->firstRow['displayName'] . </a>'; if ($this->nextRowCount > 0) { echo '<ul class=" . $this->firstRow['displayname'] . ">'; // for ($i = 0; i > $this->nextRowCount; i++) { echo '<li><a href=" . $this->nextRow['linkTo'] ."> . $this->nextRow['displayName'] . </a></li>'; } echo '</ul>'; } echo '</li>'; } } private function findNavItems ($pageIdRel = 0) { // Run the query if ($pageIdRel == 0) { private $navData = mysql_query("SELECT id, displayName, link AS linkTo FROM Ot1GiZxOysW8_pages WHERE pageIdRel IS NULL isPublic = 1 AND startDate <= now() AND endDate >= now() AND draftOnly = 0 ORDER BY itemOrder ASC"); } else { private $navData = mysql_query("SELECT id, displayName, link AS linkTo FROM Ot1GiZxOysW8_pages WHERE pageIdRel = . $pageIdRel . isPublic = 1 AND startDate <= now() AND endDate >= now() AND draftOnly = 0 ORDER BY itemOrder ASC"); } // Save the results to an array private $navDataArray = mysql_fetch_array($this->navData); // Return the array to the caller return $this->navDataArray; } } You can't use access modifiers (i.e., private, protected, public) in an inline manner. Instead, you declare or define your members with a modifier, then use them. Also, to refer to them within a function, you need to use the 'this' keyword (same goes for calling member functions within a class). So: class buildNavMenu { private $firstRow; private $nextRow; private $nextRowCount; private $itemCount; private $navData; private $navDataArray; public function __construct() { db_connect(); } public function buildMenu() { $this->firstRow = $this->findNavItems(); . . . } private function findNavItems($pageIdRel = 0) { . . . } } I don't see anything glaringly wrong (other than what I mentioned above) upon a quick first glance. Put: error_reporting(E_ALL); At the top of your page after you make the fixes I suggest and report any errors you come up with. Link to comment https://forums.phpfreaks.com/topic/123658-no-error-no-output/#findComment-638583 Share on other sites More sharing options...
ready4god2513 Posted September 10, 2008 Author Share Posted September 10, 2008 Thanks. I will check that out right away! Link to comment https://forums.phpfreaks.com/topic/123658-no-error-no-output/#findComment-638586 Share on other sites More sharing options...
ready4god2513 Posted September 10, 2008 Author Share Posted September 10, 2008 Worked perfectly. I had also forgotten to add the "$" before the index in each of the for loops. That was throwing an error for me. Thank you so much. Case Closed. Link to comment https://forums.phpfreaks.com/topic/123658-no-error-no-output/#findComment-638588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.