I caught that error, but the line number was referring to the assignment, it
didn't even get to the obvious error.

Why would  $total = $db->affected_rows, (assigning the value of
$affected_rows to $total) be interpreted as a method call?

I have since defined a num_rows() method (using mysql_num_rows()) and I have
gotten past this error, however I am still having a major problem with what
I'm trying to accomplish.

I'll post more later tonight when I get home from work... Thanks for your
help Thijs adn Darren

On Thu, Jan 7, 2010 at 3:49 AM, Thijs Lensselink <d...@lenss.nl> wrote:

> Allen McCabe 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;
>>
>
> Here you use affected_rows as a class property to assign a value to a
> variable.
>
>
>
>>        if ($total > 0)
>>        {
>>            $Link = new Link();
>>            $count = $db->affected_rows($result);
>>
>
> Here you call affected_rows as a class method. And from looking at your
> Database class. affected_rows is a property not a method. So that explains
> the undefined method error.
>
>
>
>             $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!!
>>
>>
>

Reply via email to