Jump to content

Recommended Posts

Hi am in need of abit of help from anyone,am having a problem with my latest topics file,I have an error that i can't seem to sort out.

 

Fatal error: Call to a member function fetch_array() on a non-object in C:\wamp\www\\templates\atest_topics.php on line 5

 

Here is my code thanks in advance.

<div class="nav_box"><div class="nav">Latest Topics</div>
<div class="nav_box2">
<?php
$query = yasDB_select("SELECT forumtopics.subjest,forumtopics.date,forumtopics.name,user.id,user.username,user.avatarfile.user.useavatar FROM forumtopics LEFT JOIN user ON forumtopic.name = user.username ORDER BY forumtopics.id DESC LIMIT 5");
while($row = $query->fetch_array(MYSQLI_ASSOC)){
      $id = $row['id'];
      $subject = $row['subject'];
      $date = date("m-j-y G:i");
      $username = $row['name'];
      if ($setting['seo'] == 'yes'){
      $topiclink = $setting['siteurl'].'forumtopics/'.$id.'/1.html';
      } else {
      $topiclink = $setting['siteurl'].'index.php?act=forumtopics&id='.$id;
      } if ($row['useavatar'] == '1') {
      $avatarimage = $setting['siteurl'].''.$row['avatarfile'];
      } else {
      $avatarimage = $setting['siteurl'].'useruploads/noavatar.JPG';
      } if ($setting['seo'] == 'yes') {
      $memberlink = $setting['siteurl'].'showmember/'.$id.'.html';
      } else {
      $memberlink = $setting['siteurl'].'index.php?act=showmember&id='.$id;
      }
?>
<a href="<?php echo $memberlink;?>"><img src="<?php echo $avatarimage;?>" width="40" height="40" align="center" title="<?php echo $username;?>"></a>
<a href="<?php echo $topiclink;?>"><?php echo $subject;?></a> - <?php echo $date;?><br>
<?php
}
$query->close();
?>
</div>
</div>
Edited by Davie33
Link to comment
https://forums.phpfreaks.com/topic/281452-call-to-a-member-function-fetch_array/
Share on other sites

could there be a possible error in your query 

 

  1. $query = yasDB_select("SELECT forumtopics.subjest,forumtopics.date,forumtopics.name,user.id,user.username,user.avatarfile.user.useavatar FROM forumtopics LEFT JOIN user ON forumtopic.name = user.username ORDER BY forumtopics.id DESC LIMIT 5");

 

the line i marked red and made bold the query looks off to me. I dont know if this was intentional but this seems like this is where the problem is. 

Edited by HippoZoned

No i need that so the avatar's show and username is an url to the user profile.But for some reason it messes with forum topic links and username links

 

I see what you mean user.avatarfile.user.useavatar there is a dot between them when it should be a comma

 

But still didn't solve the problem.  user.avatarfile,user.useavatar

Edited by Davie33

from what i see is you never got a result of your query. You just made the query but never asked for the result 

 

once you get the result you could write like 5 like this 

 

  1. while($row = $result->fetch_array(MYSQLI_ASSOC)){

 

once that is done it should fix the problem but first you must get the result like so

 

$result mysql_query($query);

 

or however you would need to grab the result of the query

Edited by HippoZoned

I think this is what you mean ? but at the same time still the same error.

<div class="nav_box"><div class="nav">Latest Topics</div>
<div class="nav_box2">
<?php
$result = yasDB_select("SELECT * FROM forumtopics");
if ($result->num_rows == 0){
echo 'No Topics';
} else {
$query = yasDB_select("SELECT forumtopics.subjest,forumtopics.date,forumtopics.name,forumtopics.cat,user.id,user.username,user.avatarfile,user.useavatar FROM forumtopics LEFT JOIN user ON forumtopics.name = user.username ORDER BY forumtopics.id DESC LIMIT 5");
while($row = $query->fetch_array(MYSQLI_ASSOC)) {
      $id = $row['id'];
	  $subject = $row['subject'];
	  $date = date("m-j-y G:i");
	  $username = $row['name'];
	  if ($setting['seo'] == 'yes'){
	  $topiclink = $setting['siteurl'].'forumtopics/'.$id.'/1.html';
	  } else {
	  $topiclink = $setting['siteurl'].'index.php?act=forumtopics&id='.$id;
	  } if ($row['useavatar'] == '1') {
	  $avatarimage = $setting['siteurl'].'avatars/'.$row['avatarfile'];
	  } else {
	  $avatarimage = $setting['siteurl'].'avatars/useruploads/noavatar.JPG';
	  } if ($setting['seo'] == 'yes') {
	  $memberlink = $setting['siteurl'].'showmember/'.$id.'.html';
	  } else {
	  $memberlink = $setting['siteurl'].'index.php?act=showmember&id='.$id;
	  }
?>
<a href="<?php echo $memberlink;?>"><img src="<?php echo $avatarimage;?>" width="40" height="40" align="center" title="<?php echo $username;?>"></a>
<a href="<?php echo $topiclink;?>"><?php echo $subject;?></a> - <?php echo $date;?><br>
<?php }
}
$query->close();
?>
</div>
</div>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.