Re: "Call to undefined method" on class property!?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Do you have a method in your Database class called affected_rows() ?
>From the code you have shown you only have a member variable called
affected_rows and so your call $db->fetch_array($result) is falling
over.

On Thu, Jan 7, 2010 at 8:47 AM, Allen McCabe <allenmccabe@xxxxxxxxx> wrote:
> I have a singleton database object in a global file at the top of my
> document. In most other locations I am able to access it just fine, however
> in my footer I want to loop through a properties list for links (I am saving
> links to a database, each with its own properties).
>
> Here is the code snippet that is giving me trouble:
>
> footerlinks.inc.php:
>
> <?php
>        $result = $db->query('SELECT * FROM `links` WHERE `category` =
> \'footer_navigation\';');
>        $total = $db->affected_rows;
>
>        if ($total > 0)
>        {
>            $Link = new Link();
>            $count = $db->affected_rows($result);
>            $i = 0;
>            while ($row = $db->fetch_array($result))
>            {
>                $properties = $Link->setLinkProperties($row);
>
>                $link[$i] = '<a ';
>                foreach ($properties as $prop)
>                {
>                    $link[$i] .= $prop;
>                }
>                $link[$i] .= '>';
>                $row['text'];
>                $link[$i] .= '</a>';
>
>                $i++;
>            }
>
>            $j = 0;
>            while ($j < $link)
>            {
>                echo $link[$j];
>                if ($j < $count)
>                {
>                    echo ' | ';
>                }
>
>                $j++;
>            }
>
>        }
>
>    ?>
>
> The $Link->$Link->setLinkProperties() method is defined in
>
> Link.class.php:
>
> <?php
>
> class Link {
>
>    public function setLinkProperties($rows)
>    {
>        if (!empty($row['href']))
>        {
>            $properties['href'] = 'href="' . $row['href'] . '" ';
>        }
>
>        if (!empty($row['class']))
>        {
>            $properties['class'] = 'class="' . $row['class'] . '" ';
>        }
>
>        if (!empty($row['style']))
>        {
>            $properties['style'] = 'style="' . $row['style'] . '" ';
>        }
>
>        if (!empty($row['title']))
>        {
>            $properties['title'] = 'title="' . $row['title'] . '" ';
>        }
>
>        if (!empty($row['name']))
>        {
>            $properties['name'] = 'name="' . $row['name'] . '" ';
>        }
>
>        if (!empty($row['target']))
>        {
>            $properties['target'] = 'target="' . $row['target'] . '" ';
>        }
>
>        if (!empty($row['rel']))
>        {
>            $properties['rel'] = 'rel="' . $row['rel'] . '" ';
>        }
>
>        if (!empty($row['onclick']))
>        {
>            $properties['onclick'] = 'onclick="' . $row['onclick'] . '" ';
>        }
>
>        if (!empty($row['ondblclick']))
>        {
>            $properties['ondblclick'] = 'ondblclick="' . $row['ondblclick']
> . '" ';
>        }
>
>        if (!empty($row['onmouseover']))
>        {
>            $properties['onmouseover'] = 'onmouseover="' .
> $row['onmouseover'] . '" ';
>        }
>
>        if (!empty($row['onmouseout']))
>        {
>            $properties['onmouseout'] = 'onmouseout="' . $row['onmouseout']
> . '" ';
>        }
>
>        return $properties;
>
>    } // END OF METHOD setLinkProperties
> } // END OF CLASS
>
> ?>
>
> Also for reference, the method query() in my database class sets a value for
> $affected_rows:
>
> Database.class.php:
>
> <?php
>
> class Database {
>
>    private $server   = ''; //database server
>    private $user     = ''; //database login name
>    private $pass     = ''; //database login password
>    private $database = ''; //database name
>    private $pre      = ''; //table prefix
>
>    #######################
>    //internal info
>    private $error = '';
>    private $errno = 0;
>
>    //number of rows affected by SQL query
>    public $affected_rows = 0;
>
> ...
>
> ?>
>
> This is the error I am receiving:
>
> "*Fatal error*: Call to undefined method Database::affected_rows() in *
> /home/mwclans1/public_html/components/footerlinks.inc.php* on line *9*"
>
> Please help PHP gurus!!
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux