mysql - show data from table php oop -


i have error warning show data database have code in folder classes/comment.php

<?php class comment { protected $database; public function fetch($table, $rows = '*', $where = null, $order = null)   { $result = "select {$rows} {$table}"; if ($where != null) {   $result += " {$where}"; } if ($order != null) {   $result += " order {$order}"; } return $result; } 

in index.php wrote:

<?php $comment  = new comment(); $results = $comment->fetch('', '$tablename', 'id_comment desc'); $comments = array(); while ($comment = mysql_fetch_array($results)) { $comments[] = $comment; } ?> <?php foreach ($comments $comment) : ?>     <div class="box-comment">       <div class="content">         <?php echo h($comment['content']) ?>             </div>       <div class="date-time">         <?php echo $comment['posted_at'] ?>            </div>     </div>   <?php endforeach ?> 

but code getting error, please me

try execute first query. guess $results return sql query string, suggest use this:

$result = mysql_query($results);

then can fetch data using:

while ($comment = mysql_fetch_array($results)) { $comments[] = $comment; }

reference: http://php.net/manual/en/function.mysql-fetch-array.php

my advice learn mysqli since mysql deprecated in php 5.5.0, , removed in php 7.0.0

tutorials of mysqli: http://www.w3schools.com/php/php_ref_mysqli.asp


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -