Van Miggy
Van Miggy

Reputation: 23

Fatal error: Call to a member function mysql_query() on resource in line 30

It seems I am more annoyed about this problem which I can't figured out why this happens. Any help is much appreciated. Here is my code:

  <?php include('header.php'); ?>
  <body>

     <table cellpadding="0" cellspacing="0" border="0" class="table" id="">
                    <thead>
                          <tr>
                              <th>Date</th>
                              <th>User</th>
                              <th>Action</th>
                              </tr>                                         
                    </thead>
                    <tbody>

              <?php
                     $query = $link->mysql_query("select * from  activity_log ORDER BY activity_log_id DESC")or die(mysql_error());
                  while($row = $query->fetch()){
                ?>

                                <tr>
                                       <td><?php  echo $row['date']; ?></td>
                                       <td><?php echo $row['username']; ?></td>
                                       <td><?php echo $row['action']; ?></td> 
                                </tr>
                        <?php } ?>

Upvotes: 0

Views: 3699

Answers (2)

Abdulla Nilam
Abdulla Nilam

Reputation: 38609

Just use

$query = mysql_query("select * from  activity_log ORDER BY activity_log_id DESC");
if (!$query) {
    die('Invalid query: ' . mysql_error());
}

then in while loop

while($row = mysql_fetch_assoc($query))

Read The mysql_query manual and Read The mysql_fetch_assoc manual

Note
This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

  1. mysqli_query()
  2. PDO::query()

Upvotes: 1

sujivasagam
sujivasagam

Reputation: 1769

Use

$query = mysql_query("select * from  activity_log ORDER BY activity_log_id DESC")or die(mysql_error());
while($row = mysql_fetch_assoc($query)){

instead of

$query = $link->mysql_query("select * from  activity_log ORDER BY activity_log_id DESC")or die(mysql_error());
while($row = $query->fetch()){

Upvotes: 0

Related Questions