Davie33 Posted August 22, 2013 Share Posted August 22, 2013 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> Link to comment https://forums.phpfreaks.com/topic/281452-call-to-a-member-function-fetch_array/ Share on other sites More sharing options...
HippoZoned Posted August 22, 2013 Share Posted August 22, 2013 could there be a possible error in your query $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. Link to comment https://forums.phpfreaks.com/topic/281452-call-to-a-member-function-fetch_array/#findComment-1446226 Share on other sites More sharing options...
Davie33 Posted August 22, 2013 Author Share Posted August 22, 2013 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 Link to comment https://forums.phpfreaks.com/topic/281452-call-to-a-member-function-fetch_array/#findComment-1446228 Share on other sites More sharing options...
HippoZoned Posted August 22, 2013 Share Posted August 22, 2013 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 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 Link to comment https://forums.phpfreaks.com/topic/281452-call-to-a-member-function-fetch_array/#findComment-1446233 Share on other sites More sharing options...
Davie33 Posted August 22, 2013 Author Share Posted August 22, 2013 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> Link to comment https://forums.phpfreaks.com/topic/281452-call-to-a-member-function-fetch_array/#findComment-1446234 Share on other sites More sharing options...
trq Posted August 22, 2013 Share Posted August 22, 2013 You should check to see that $query is indeed what you expect it to be before you go ahead and use it like its an object. $query seems a silly thing to name it too, its not a query. Link to comment https://forums.phpfreaks.com/topic/281452-call-to-a-member-function-fetch_array/#findComment-1446236 Share on other sites More sharing options...
Davie33 Posted August 22, 2013 Author Share Posted August 22, 2013 Sorry am abit tired need my sleep its just not working for me atm. Link to comment https://forums.phpfreaks.com/topic/281452-call-to-a-member-function-fetch_array/#findComment-1446239 Share on other sites More sharing options...
Twysted Posted August 22, 2013 Share Posted August 22, 2013 try using a num_rows method in your sql and then using an if statement to check if the query was successful. if the if statement you can add the while loop. Link to comment https://forums.phpfreaks.com/topic/281452-call-to-a-member-function-fetch_array/#findComment-1446262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.