Yush
Yush

Reputation: 48

Creating link in table row from mysql in php (member list)

I am trying to create a member list where all the users from the database will show in a table and each table will contain their profile link under their name.

but I am getting Fatal error: Cannot use object of type stdClass as array

here is my code

mysql_select_db('members',$connection) or die(mysql_error());

//execute a mysql query to retrieve all the users from users table

$query=mysql_query("SELECT * FROM members") or die(mysql_error());

//if we get any results we show them in table data

if(mysql_num_rows($query)>0):


<table cellspacing="0" id="tech-companies">
   <thead>
      <tr>
         <th class="persist essential">Name</th>
         <th class="essential">Status</th>
         <th class="essential">Balance</th>
         <th class="essential">Balance Updated</th>
         <th class="optional">Member Type</th>
         <th class="optional">Mobile</th>
         <th class="optional">Gender</th>
         <th class="optional">ID</th>
         <th class="optional">Last Logged in</th>
      </tr>
   </thead>



  <tbody>
     <?php 
  //while we going through each row we display info
  //echo $row['id'];
  while($row=mysql_fetch_object($query)):?>
  <tr>
    <th align="center">


<?php 

---- Here is where I am trying to show the link of users...

echo $row->name; echo'<br/><span><a href="#">edit</a> | 
<a href="id=' . $row['id'] . '">view</a></span>'; //row id ?></th>    

---- And the lasts are working fine..

<td align="center"><?php echo $row->locked; ?></td>
<td align="center"><?php echo $row->balance;  ?></td>
<td align="center"><?php echo $row->lbu; ?></td>
<td align="center"><?php echo $row->mcat; ?></td>
<td align="center"><?php echo $row->mobile; ?></td>
<td align="center"><?php echo $row->sex; ?></td>
<td align="center"><?php echo $row->id; ?></td>
<td align="center"><?php echo $row->lastlogin; ?></td>


 </tr>
  <?php endwhile;?>
   </tbody>
</table>
<br/>
<?php 
//if we can't get results we show information
else: ?>
<h3>No Results found.</h3>
<?php endif; ?>

Upvotes: 0

Views: 1860

Answers (2)

Jacob Ewing
Jacob Ewing

Reputation: 768

I believe your problem's here:

<a href="id=' . $row['id'] . '">view</a></span>'; //row id ?></th> 

and should instead be:

<a href="id=' . $row->id . '">view</a></span>'; //row id ?></th>   

Upvotes: 2

ryrysz
ryrysz

Reputation: 907

correct line:

  <a href="id=' . $row['id'] . '">view</a></span>'; //row id ?></th>  

to:

  <a href="id=' . $row->id . '">view</a></span>'; //row id ?></th>  

Upvotes: 2

Related Questions