Note that there are some explanatory texts on larger screens.

plurals
  1. POfunction rowCount() on a non-object error
    primarykey
    data
    text
    <p>I keep getting an <strong><code>function rowCount() on a non-object</code></strong> error on two different pages. Any idea why this is happening and how I can alter the code to prevent it from happening?</p> <p><strong>Error - as below</strong> </p> <pre><code>Fatal error: Call to a member function rowCount() on a non-object in /opt/lampp/htdocs/xampp/index.php on line 35 </code></pre> <p><strong>The code:</strong></p> <pre><code>$sql = "SELECT * from idea ORDER BY datetime DESC LIMIT 50;"; $result = $pdo-&gt;query($sql); if($result-&gt;rowCount() &gt; 0 &amp;&amp; !empty($result)) // line 35 { foreach ($result as $row) { $id = $row['id']; $title = $row['title']; $idea = $row['idea']; echo '&lt;span class="idea" id="'.$id.'"&gt;&lt;strong style="color: #0081C5"&gt;' . $title . "&lt;/strong&gt;&amp;nbsp;-&amp;nbsp;" . $idea . '&amp;nbsp;&lt;a class="delete" href="#"&gt;[Delete]&lt;/a&gt;&lt;/span&gt;'; } } </code></pre> <p><strong>Error - as below</strong></p> <p><strong><code>Fatal error: Call to a member function rowCount() on a non-object in /opt/lampp/htdocs/xampp/assets/update.php on line 6</code></strong></p> <p><strong>The code</strong></p> <pre><code> $sql = "SELECT * from idea ORDER BY datetime DESC LIMIT 50;"; $result = $pdo-&gt;query($sql); if($result-&gt;rowCount() &gt; 0 &amp;&amp; !empty($result)) // line 6 { foreach ($result as $row) { $id = $row['id']; $title = $row['title']; $idea = $row['idea']; echo '&lt;span class="idea" id="'.$id.'"&gt;&lt;strong style="color: #0081C5"&gt;' . $title . "&lt;/strong&gt;&amp;nbsp;-&amp;nbsp;" . $idea . '&amp;nbsp;&lt;a class="delete" href="#"&gt;[Delete]&lt;/a&gt;&lt;/span&gt;'; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload