Jump to content
MakeWebGames

database::fetch_array..........


peterisgb

Recommended Posts

I keep this this error on loads of pages. Please help and thanks in advance :)

Error Code is

Fatal error: Call to undefined method database::fetch_array() in /home/electri9/public_html/viewuser.php on line 251

lines 244 - 263

 

print"<table width=100% cellspacing=1 class='table'><tr style='background:gray'><th colspan=2>Users Comments <A href=comments.php?ID={$r['userid']}>[Add Comment]</a></th>";
if($ir['userid'] == $r['userid'] || $ir['user_level'] > 1)
{
print"<th width=10%>Delete</th>";
}
print"</tr>";
$blah=$db->query("SELECT * FROM comments WHERE cmtTO={$r['userid']} ORDER BY cmtTIME DESC limit 5", $c) or die(mysql_error());
while($cmnt = $db->fetch_array($blah));
{
$they=$db->query("SELECT * FROM users WHERE userid={$cmnt['cmtFROM']}",$c);
$them=$db->fetch_array($they);
$sent=date('F j, Y, g:i:s a',$cmnt['cmtTIME']);
print"<td width=25%><b>{$them['username']} [{$them['userid']}]</br></br></b>$sent</td><Td>{$cmnt['cmtTEXT']}</td>";
if($ir['userid'] == $r['userid'] || $ir['user_level'] > 1)
{
print"<td width=10%><a href=comments.php?action=delete&ID={$cmnt['cmtID']}>Delete</a></td>";
}
print"</tr>";
}
print"</table>";
Edited by peterisgb
Code Tag in wrong place
Link to comment
Share on other sites

You most likely using MCCodes.

$db->fetch_array does not exist. I presume that is meant to be mysql_fetch_array.

In MCCodes V2, mysql_fetch_array = $db->fetch_row

 

echo "<table width='100%' cellspacing='1' class='table'><tr style='background:gray'><th colspan='2'>Users Comments 
<a href='comments.php?ID={$r['userid']}'>[Add Comment]</a></th>";
if($ir['userid'] == $r['userid'] || $ir['user_level'] > 1)
{
echo "<th width='10%'>Delete</th>";
}
echo "</tr>";
$query = $db->query("SELECT * FROM `comments` WHERE `cmtTO`={$r['userid']} ORDER BY `cmtTIME` DESC limit 5", $c) or die($db->error());
while($cmnt = $db->fetch_row($query));
{
$they=$db->query("SELECT `userid`, `username` FROM `users` WHERE `userid`={$cmnt['cmtFROM']}",$c);
$them=$db->fetch_row($they);
$sent=date('F j, Y, g:i:s a',$cmnt['cmtTIME']);
echo "<td width='25%'><b>{$them['username']} [{$them['userid']}]</br></br></b>$sent</td><Td>{$cmnt['cmtTEXT']}</td>";
if($ir['userid'] == $r['userid'] || $ir['user_level'] > 1)
{
echo "<td width='10%'><a href='comments.php?action=delete&ID={$cmnt['cmtID']}'>Delete</a></td>";
}
echo "</tr>";
}
echo "</table>";

 

Try that out.

Edited by Samurai Legend
Link to comment
Share on other sites

oh right ok, well i cant use that either as it throws up another error to do with the class_db_mysqli.php which MTG wrote. will have get his help there.

Why are you using MTG's code?... Out of curiosity :)

Link to comment
Share on other sites

try using

 

mysql_fetch_array();

I appreciate you trying to help but when giving advice, please research your answer before giving it. mysql_* is depreciated, as he is using MCCodes, then the correct way of doing it would be to rely on the database wrapper included in MCCodes.

Link to comment
Share on other sites

I appreciate you trying to help but when giving advice, please research your answer before giving it. mysql_* is depreciated, as he is using MCCodes, then the correct way of doing it would be to rely on the database wrapper included in MCCodes.

I know mysql is depreciated i simply gave a simple solution they could infact use the McCodes Classes but apparently this class doesn't exist. why dont you provide the non depreciated fix !Angel? seeing you know what your saying pfft

Link to comment
Share on other sites

I know mysql is depreciated i simply gave a simple solution they could infact use the McCodes Classes but apparently this class doesn't exist. why dont you provide the non depreciated fix !Angel? seeing you know what your saying pfft

I was actually pointing it out to help you, the class does exist, but the method does not. Generally yes I like to think I know what I am talking about, however I believe Samurai gave the correct solution.

Link to comment
Share on other sites

While I'm sure Samurai's solution is provided in good faith, anybody making the mistaken assumption that that is a correct solution really needs to take a step back and consider the problem at hand. The database engine mysql / mysqli can be considered unimportant here; many hosts still run mysql and will continue to do so for some time in order to provide support to legacy applications - and while mysqli is certainly a much better interface, providing for instance the ability to call stored-procedures and the ability to use prepared queries, it's SQL injection prevention is little different especially in how people use it.

If people actually looked at the problem and spent a moment to try and understand what is happening underneath and how it could be improved, platforms like the venerable McCodes would perhaps have a lot more following with people willing to provide decent modifications both free and commercial. As it stands, this code is a mess, it falls into the old McCodes way of doing things with no separation of display logic versus data extraction versus program flow. There's also the poor use of SQL - Why 6 queries to do something that is easy in one? Yes, I know the OP posted that mechanism but surely the community (and by that I point an accusing finger towards at least two posters in this topic) should try and improve both their own and other peoples skills by posting clean code, with well written logically thought out SQL.

I know plenty of people of have learned a great deal from these forums thankfully, I speak to one or two on a regular basis, and I have also seen their skills improve considerable over the period I've known them. The assistance they were given comes in part from analyzing the poor quality of code presented in posts like this, discussing it in detail, looking at what sort of problems may exist, and dealing with them. Is it so hard for people to do this? Too many times staff or ""community leaders"" have their word accepted as fact, when in reality their ideas and statements can be misread - and I accept that I have to include myself in that.

For reference consider the query:

   SELECT c.cmtTIME, u.username, u.userid, c.cmtTEXT /* other fields to suit */
    FROM comments c
LEFT JOIN users u ON c.cmtFROM = u.userid
   WHERE c.cmtTO = $userid
ORDER BY c.cmtTIME DESC
   LIMIT 5
Link to comment
Share on other sites

While I'm sure Samurai's solution is provided in good faith, anybody making the mistaken assumption that that is a correct solution really needs to take a step back and consider the problem at hand. The database engine mysql / mysqli can be considered unimportant here; many hosts still run mysql and will continue to do so for some time in order to provide support to legacy applications - and while mysqli is certainly a much better interface, providing for instance the ability to call stored-procedures and the ability to use prepared queries, it's SQL injection prevention is little different especially in how people use it.

If people actually looked at the problem and spent a moment to try and understand what is happening underneath and how it could be improved, platforms like the venerable McCodes would perhaps have a lot more following with people willing to provide decent modifications both free and commercial. As it stands, this code is a mess, it falls into the old McCodes way of doing things with no separation of display logic versus data extraction versus program flow. There's also the poor use of SQL - Why 6 queries to do something that is easy in one? Yes, I know the OP posted that mechanism but surely the community (and by that I point an accusing finger towards at least two posters in this topic) should try and improve both their own and other peoples skills by posting clean code, with well written logically thought out SQL.

I know plenty of people of have learned a great deal from these forums thankfully, I speak to one or two on a regular basis, and I have also seen their skills improve considerable over the period I've known them. The assistance they were given comes in part from analyzing the poor quality of code presented in posts like this, discussing it in detail, looking at what sort of problems may exist, and dealing with them. Is it so hard for people to do this? Too many times staff or ""community leaders"" have their word accepted as fact, when in reality their ideas and statements can be misread - and I accept that I have to include myself in that.

For reference consider the query:

   SELECT c.cmtTIME, u.username, u.userid, c.cmtTEXT /* other fields to suit */
    FROM comments c
LEFT JOIN users u ON c.cmtFROM = u.userid
   WHERE c.cmtTO = $userid
ORDER BY c.cmtTIME DESC
   LIMIT 5

It's midnight, probably got the wrong end of the stick, but he posted an MCCodes problem, he uses MTG's code. Samarai told him how MCCodes does it, and your saying the MCCodes way is wrong?

Link to comment
Share on other sites

While I'm sure Samurai's solution is provided in good faith, anybody making the mistaken assumption that that is a correct solution really needs to take a step back and consider the problem at hand. The database engine mysql / mysqli can be considered unimportant here; many hosts still run mysql and will continue to do so for some time in order to provide support to legacy applications - and while mysqli is certainly a much better interface, providing for instance the ability to call stored-procedures and the ability to use prepared queries, it's SQL injection prevention is little different especially in how people use it.

... as you said mysql vs mysqlI has nothing to do with this error.

If people actually looked at the problem and spent a moment to try and understand what is happening underneath and how it could be improved, platforms like the venerable McCodes would perhaps have a lot more following with people willing to provide decent modifications both free and commercial. As it stands, this code is a mess, it falls into the old McCodes way of doing things with no separation of display logic versus data extraction versus program flow. There's also the poor use of SQL - Why 6 queries to do something that is easy in one? Yes, I know the OP posted that mechanism but surely the community (and by that I point an accusing finger towards at least two posters in this topic) should try and improve both their own and other peoples skills by posting clean code, with well written logically thought out SQL.

If you have the time I invite you to help the OP with the page. Not everyone has the time.

I know plenty of people of have learned a great deal from these forums thankfully, I speak to one or two on a regular basis, and I have also seen their skills improve considerable over the period I've known them. The assistance they were given comes in part from analyzing the poor quality of code presented in posts like this, discussing it in detail, looking at what sort of problems may exist, and dealing with them. Is it so hard for people to do this? Too many times staff or ""community leaders"" have their word accepted as fact, when in reality their ideas and statements can be misread - and I accept that I have to include myself in that.

The main reason I am posting - should I be insulted by this? I am basically reading that as one of two things either people are not challenging others enough (fair enough I guess) or the staff members/community leaders (who are who exactly?) are giving out bad information...

Link to comment
Share on other sites

...either people are not challenging others enough (fair enough I guess) or the staff members/community leaders (who are who exactly?) are giving out bad information...
I'd say yes to both in fact. It's not a criticism aimed at anyone specifically, rather a simple generalization. The key point I was trying to impart is that the accepted solution is far from ideal, it compounds the poor thinking, and subsequent shoddy code seen all too commonly with the engine. If people who regularly post to the forum state something as fact, then whether it is valid, correct or even useful can easily become irrelevant - other members are liable to accept it in good faith without realizing that there are often multiple alternative solutions, some no doubt better - and equally some in all likelihood worse.

As for helping, I see no benefit in giving the answer verbatim, I prefer as has no doubt been observed on many occasions, to give hints that force people to think. If only a few people can understand these somewhat obscure hints, I can live with it - programming is not for everybody and people need to realize that they need to really work at it in order to get rewarded be it financially or simply personal satisfaction.

Going back to the original problem, I'd suggest that anybody using the same software try out the SQL query I posted above, and endeavor to mold to to their own specific needs; how it's called - by whatever interface - is as you rightly point out, irrelevant Understanding how it works however is highly beneficial.

Link to comment
Share on other sites

I'd say yes to both in fact. It's not a criticism aimed at anyone specifically, rather a simple generalization. The key point I was trying to impart is that the accepted solution is far from ideal, it compounds the poor thinking, and subsequent shoddy code seen all too commonly with the engine. If people who regularly post to the forum state something as fact, then whether it is valid, correct or even useful can easily become irrelevant - other members are liable to accept it in good faith without realizing that there are often multiple alternative solutions, some no doubt better - and equally some in all likelihood worse.

As for helping, I see no benefit in giving the answer verbatim, I prefer as has no doubt been observed on many occasions, to give hints that force people to think. If only a few people can understand these somewhat obscure hints, I can live with it - programming is not for everybody and people need to realize that they need to really work at it in order to get rewarded be it financially or simply personal satisfaction.

I didn't find the answer you gave obscure at all, but the comments about the MWG members? That really was. If you want to challenge a post on the forum you're free to do so as is anyone else (in a respectful manner of course). Don't patronize other members because you either don't think they are trying hard enough or because they aren't the same level as yourself. It's equally as harmful as bad information as it makes them hesitate to ask questions here... and they ask elsewhere.

 

Going back to the original problem, I'd suggest that anybody using the same software try out the SQL query I posted above, and endeavor to mold to to their own specific needs; how it's called - by whatever interface - is as you rightly point out, irrelevant Understanding how it works however is highly beneficial.

You pointed it out not me. I haven't actually comment on the OP at all.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...