Array Output Trouble?

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
maddenuk
Forum Commoner
Posts: 27
Joined: Fri May 18, 2007 3:07 am

Array Output Trouble?

Post by maddenuk »

I've been trying to get this news section i had paid someone to write for me. I'm pretty up-to-date with PHP however the news archive section wont work. I've narrowed down that the error is in the indexController.php file which is where the functions for this section are located. I've narrowed it down to line 39 as it is outputing a empty array. What i am unsure about is why it is doing this. Could anybody give me any pointers? Cheers

http://creativebubbles.co.uk/news/

Code: Select all

<?php

require_once 'Zend/Controller/Action.php';


class IndexController extends Zend_Controller_Action
{
    /**
     * Init all needed data, get today's date (required to calculate few things)
     * 
     * @access public
     * @return
     */
    public function init() 
    { 
    Zend_Loader::loadClass('News'); 
	$view = Zend_Registry::get('view');
	$view->siteurl = Zend_Registry::get('site-url'); 
	
	$dToday = date("Y-m-d");
	list($sYear,$sMonth,$sDay) = split('-',$dToday);
	
	$db = Zend_Registry::get('db'); 
	
	$obb = new News();
	
	if ($sMonth <= 10){ 
	    $LastMonth = "0%d";
	    $returnLastMoth = sprintf ($LastMonth, $sMonth - 1);
	} else {
	    $returnLastMoth = $sMonth - 1;
	}
	
	$where = $db->quoteInto("month = ?", $this->getMonth($sMonth));
	$view->lastnews = $obb->fetchAll();
	
	$com = $obb->getAdapter()->query("SELECT date, month, year FROM `news` WHERE id >0 GROUP BY month  ORDER BY `news`.`date` DESC", 0);
	
	$view->archive = $com->fetchAll();
	
	// $oLastMonth = $db->query("SELECT * FROM news WHERE DATE_FORMAT(date, '%m') = '$returnLastMoth'");
	// $asd = $oLastMonth->fetchAll();
	// $view->previousMonth = $asd[0];
	//print_r($view->previousMonth);
	$where = $db->quoteInto("month = ?", $this->getMonth($returnLastMoth));
	$view->previousMonth = $obb->fetchAll();
	print_r($view->archive);
	
    }
    
    function getMonth($m=0) {
        return (($m==0 ) ? date("F") : date("F", mktime(0,0,0,$m)));
    }    
    
    /**
     * We have to set up what is going to happen if action specified by user
     * doesn't exist. In our case it will redirect to main page
     *
     * @param mixed $action
     * @param array $arguments
     * @access public
     * @return
     */
    public function __call($action, $arguments)
    {
        $this->_redirect('/');
    }
    
    
    /**
     * Display single post
     *
     * @access public
     * @return 
     */
    public function viewAction() {
        $view = Zend_Registry::get('view');
        $title = $this->_getParam('title');
	$year = $this->_getParam('year');
	$month = $this->_getParam('month');
        try
        {
            $table = new News();
            $row = $table->fetchRow('year = "'.$year.'"');
	    $row = $table->fetchRow('month = "'.$month.'"');
	    $row = $table->fetchRow('url = "'.$title.'"');
        } catch (Exception $e)
        { //handle exceptions
        
        }
        $view->title = $row->title;
        $view->body= $row->body;
	$view->date = $row->date;
	$view->url = $title;
	$view->year = $row->year;
	$view->month = $row->month;
	$view->day = $row->day;
	$view->author = $row->author;
        
	if ($row->url != ''){
        $view->actionTemplate = 'indexView.tpl.php';
        $this->_response->setBody($view->render('site.tpl.php'));
	} else {
	    $this->_redirect('/'); 
	}
        
        }
        

    /**
     * Display list of posts on the main page
     *
     * @access public
     * @return 
     */    
    function indexAction()
    {
	$view = Zend_Registry::get('view'); 

	
		$db = Zend_Registry::get('db'); 
		$obb = new News();
		
	    $select = $db->select()->from('news')->order('date DESC');
		$stmt = $select->query();
		$view->albums = $stmt->fetchAll();
		
        $view->actionTemplate = 'indexIndex.tpl.php'; 
        $this->_response->setBody($view->render('site.tpl.php')); 
    }

}

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"><!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2000281-1";
urchinTracker();
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Web Design & Graphic Design Agency in Nottingham, UK</title>
<link rel="stylesheet" type="text/css" href="<?php echo $this->escape($this->siteurl); ?>/css/sddm.css" />
<!-- InstanceEndEditable -->
<link rel="icon" href="../../../Templates/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="../../../Templates/favicon.ico" type="image/x-icon" />
<link href="http://www.creativebubbles.co.uk/css/styles.css" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://www.creativebubbles.co.uk/creative-bubbles-news.rss" />
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<body>
	<div id="maincontainer">
		
		<div id="topNav">
			<p>
				<a href="../../../" accesskey="h" title="Creative Bubbles graphic design, marketing and web design agency"><em>H</em>ome</a> | 
				<a href="../../../about/" accesskey="a" title="About Creative Bubbles expertise in design, marketing and web design"><em>A</em>bout Us</a> |	
				<a href="../../../case-studies/" accesskey="s" title="Information about work Creative Bubbles has done for our clients from design, marketing and web design">Case <em>S</em>tudies</a> | 
				<a href="../../../our-work/" accesskey="o" title="The work Creative Bubbles does in print, marketing and web design"><em>O</em>ur Work</a> | 	
				<a href="../../../news/" accesskey="n" title="News about what Creative Bubbles is doing in the web industry from print, marketing, web and graphic design"><em>N</em>ews</a> | 
				<a href="../../../contact-us/" accesskey="c" title="Contact Us for information or getting a quote"><em>C</em>ontact Us</a>			</p>
	  </div>
		
		<div id="header">
			<img src="http://www.creativebubbles.co.uk/images/site/logo.jpg" alt="Creative Bubbles Logo" width="192" height="109" id="logo" title="Creative Bubbles" /><!-- InstanceBeginEditable name="EditRegion2" -->
			<div id="quickNavigation">
              <p>Quick Navigation: <a href="../../../index.php" accesskey="h" title="Creative Bubbles graphic design, marketing and web design agency">Home</a></p>
		    </div>
			<!-- InstanceEndEditable --></div>
		

		
		
		
		
		
   		<!-- Content -->
	  <div id="content">
	  	  	<div id="greyLine"></div>

	  
	  <!-- InstanceBeginEditable name="EditRegion1" -->
		  <div id="quickNav">
            <p>Quick Navigation: <a href="<?php echo $this->escape($this->siteurl); ?>/index.php">Home</a> ><a href="index.php"> News </a></p>
	      </div>
		  <!-- Content -->
          <div id="content">
           
			
            <div id="newsMenu">
		
		    <p class="pageTitle">News Archive</p>
			
		  <div class="navbar">
		
			<!-- *********************************Start Menu****************************** -->
			 <?php foreach($this->archive as $single=> $val) : ?> 
			
			<div class="mainDiv" >
			<div class="topItem" ><?php echo ucfirst($this->escape($val['month'])); ?> <?php echo ucfirst($this->escape($val['year'])); ?></div>        
			<div class="dropMenu" ><!-- -->
				<div class="subMenu">
                                        <?php foreach($this->lastnews as $singlenews) : ?> 
										<?php if ($singlenews->month == $val['month']) { ?>
					<div class="subItem"><a href="<?php echo $this->escape($this->siteurl); ?>/news/<?php echo $this->escape($singlenews->year);?>/<?php echo $this->escape($singlenews->month);?>/<?php echo $this->escape($singlenews->url);?>"><?php echo $singlenews->title; ?></a></div>
                                        <?php } ?>
										<?php endforeach; ?> 
			  </div>
			</div>
			</div>
			
			 <?php endforeach; ?> 
			
			<!-- *********************************End Menu****************************** -->
			<script type="text/javascript" src="<?php echo $this->escape($this->siteurl); ?>/scripts/xpmenuv21.js"></script>
		</div>
			<p>Keep up to date with the latest news from Creative Bubbles by subscribing to our <a href="<?php echo $this->escape($this->siteurl); ?>/creative-bubbles-news.rss">RSS Feed</a>	        </p>
  	  </div>

 <?php echo $this->render($this->actionTemplate); ?> 



	
	  
          </div>
		  <!-- InstanceEndEditable -->	  
	  
	  </div>
		
		<!-- Footer -->
		
		<div id="footer">
			<div id="address">
			  <p>Creative Bubbles, Creative Studio <br />
53 Eccles Way, Nottingham NG3 3DG<br />
			  </p>
		  </div>	
			<div id="contactDetails">
				<p>Telephone: 0871 918 0 955 <br />
Email: <a href="mailto:info@creativebubbles.co.uk">info@creativebubbles.co.uk</a></p>
		  </div>
		</div>
		
		<div id="tools">
			<div id="furtherLinks">
				<p><a href="../../../accessibility/" title="Information regarding Accessbility" accesskey="0">Accessibility</a> | <a href="../../../sitemap/" title="Sitemap for the Creative Bubbles website" accesskey="m">Site<em>m</em>ap</a> | <a href="../../../terms-of-business/" accesskey="t" title="Creative Bubbles Terms & Conditions"><em>T</em>erms of Business</a> | <a href="../../../privacy/" title="Creative Bubbles Privacy Policy">Privacy Policy </a></p>	
			</div>
			<div id="xhtmldec">
				<a href="http://validator.w3.org/check?uri=referer" title="This Page Conforms to W3C Web Standards Valid XHTML" target="_blank"><img src="http://www.creativebubbles.co.uk/images/site/validxhtml.gif" alt="Valid XHTML Document" title="This Page Conforms to W3C Web Standards Valid XHTML" /></a> <a href="http://jigsaw.w3.org/css-validator/check/referer" title="This Page Uses a Valid CSS Document According to W3C Standards" target="_blank"><img src="http://www.creativebubbles.co.uk/images/site/validcss.gif" alt="Valid CSS Document" title="This Page Uses a Valid CSS Document According to W3C Standards" /></a>			
			</div>	
		</div>
	
	
	
	</div>
</body>
<!-- InstanceEnd --></html>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

What line is 39 again?
maddenuk
Forum Commoner
Posts: 27
Joined: Fri May 18, 2007 3:07 am

Post by maddenuk »

ha! sorry..

Line 39 is..

Code: Select all

$view->archive = $com->fetchAll();
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I think that query is failing because it has reserved MySQL keywords in it.

Try this..

Code: Select all

$com = $obb->getAdapter()->query("SELECT `date`, `month`, `year` FROM `news` WHERE `id` > 0 GROUP BY `month`  ORDER BY `date` DESC", 0);
maddenuk
Forum Commoner
Posts: 27
Joined: Fri May 18, 2007 3:07 am

Post by maddenuk »

i though that too but i did try that and have done so again to no success. Any other ideas?

Cheers
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

No clue. I don't use Zend.

My best guess is to find the fetchAll() method and go from there, but like I said, I have never used Zend before. Someone else might be able to help you further.
Post Reply