Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: SA™ on April 12, 2008, 03:15:40 AM

Title: need little help changing this code to work with smf 2.0
Post by: SA™ on April 12, 2008, 03:15:40 AM
cam somone please help me chang this to work with smf 2 i have tried but with no luck i got to the point where i am going to punch the crap out of my pc soon so fault ill ask here hope you can help thanks

wayne




function ArcadeStats_BestPlayers($count = 10)
{
global $db_prefix, $scripturl, $txt;
$res = $smcFunc['db_query']('', '
SELECT count(*) AS champions, IFNULL(mem.ID_MEMBER, 0) AS ID_MEMBER, IFNULL(mem.realName, '') AS realName, IFNULL(mem.avatar, '') AS avatar
FROM {$db_prefix}arcade_games AS game
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = game.ID_MEMBER_CHAMPION)
WHERE ID_CHAMPION_SCORE > 0
GROUP BY game.ID_MEMBER_CHAMPION
ORDER BY champions DESC 
LIMIT 0',$count", __FILE__, __LINE__);

$top = array();
$max = -1;

while ($score =$smcFunc['db_fetch_assoc']($res))


{
if ($max == -1)
$max = $score['champions'];

$top[] = array(
'name' => $score['realName'],
'avatar' => $score['avatar'],
'link' => !empty($score['realName']) ? '<a href="' . $scripturl . '?action=profile;u=' . $score['ID_MEMBER'] . '">' .  $score['realName'] . '</a>' : $txt['arcade_guest'],
'champions' => $score['champions'],
'precent' => ($score['champions'] / $max) * 100,
);
}

if (count($top) == 0)
return false;
elseif ($count > 1)
return $top;
else
return $top[0];
}
$top_player = ArcadeStats_BestPlayers(10);
$i=0; //players position

//array for icons
$poz = array('/first.gif','/second.gif','/third.gif','/fourth.gif','/fifth.gif','/sixth.gif','/seventh.gif','/eigth.gif','/ninth.gif','/tenth.gif');

echo '
<table width="100%" border="0" cellpadding="1">
<tr>
<td class="titlebg" colspan="10"><div align="center"><b>Top 10 Arcade Champions</b></div></td></tr><tr></br></tr><tr>';
foreach ($top_player as $row)
{
echo '

<td><div align="center"><img src="http://waynesworld.kicks-ass.net/forum/Themes/BlackRainv11/images/arc_icons',$poz[$i] , '"/><br/><br/>
<img src="avatars/', $row['avatar'],'"><br/>
',$row['link'],'<br/>
',$row['champions'],' </div></span></td>
';
$i++;
}

echo'</tr><tr></br></tr><tr></br></tr><tr></br></tr><tr></br></tr></table></div>';

     


edit ok i been fidling a bit more and got this far and get this error
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\*******\htdocs\champs.php on line 18
Title: Re: need little help changing this code to work with smf 2.0
Post by: karlbenson on April 12, 2008, 12:34:50 PM
I suspect its failing on
IFNULL(mem.realName, '')

You can't use single quotes inside the query.
Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 12, 2008, 04:53:48 PM
sry im still learning about mysql and stuff so how would i do it?
Title: Re: need little help changing this code to work with smf 2.0
Post by: SleePy on April 12, 2008, 05:01:17 PM
You would need to change that to use double quotes

IFNULL(mem.realName, "")

The same would apply for the avatar.

As well as the other quotes.

Where did you get the original from?

http://www.simplemachines.org/community/index.php?topic=224166.0
Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 12, 2008, 05:07:22 PM
yes i got the origanal from there ill try that and see what happens thanks
Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 12, 2008, 05:10:34 PM
ok done that now i get this

Parse error: syntax error, unexpected '"' in C:\******\htdocs\champs.php on line 24


edit i changed this

LIMIT 0',$count", __FILE__, __LINE__);

to

LIMIT 0',$count, __FILE__, __LINE__);

now i get

Fatal error: Function name must be a string in C:\******\htdocs\champs.php on line 17


Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 14, 2008, 12:54:26 AM
bump changed the code again globld it and now i het this


Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in C:\*******\htdocs\forum\Sources\Subs-Db-mysql.php on line 418

Warning: mysql_errno(): supplied argument is not a valid MySQL-Link resource in C:\*******\htdocs\forum\Sources\Subs-Db-mysql.php on line 419

Database Error

File: C:\******\htdocs\champs.php
Line: 25 


line 25 is this 

   LIMIT 0',$count, __FILE__, __LINE__);

please somone help thanks



Title: Re: need little help changing this code to work with smf 2.0
Post by: Bulakbol on April 14, 2008, 01:09:44 AM
It looks like the original is from an arcade mod. Maybe better to ask the author of the mod.
Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 14, 2008, 02:28:51 AM
no the code has nothing to do with the auther so i dont see how that will help
the code works fine with the arcade it was upuntill i upgraded what i want is for somone to help me update it to work with smf 2.0 i iknow for a fact that it works with e arcade 2.5.0 just not smf 2.0 as it worked well with 1.1.4

thanks wdm
Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 14, 2008, 02:07:14 PM
i give up seen as nobody wants to help  :(
Title: Re: need little help changing this code to work with smf 2.0
Post by: Bulakbol on April 15, 2008, 01:01:23 AM
The mod you are trying to install is for 1.1.4. It has to be updated to work with 2.0 that's why you have to ask the author to update it.
Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 15, 2008, 01:26:16 AM
what im not installing nothing lol its a script thats all not no mod al i wanted is for it to be updated to work with smf 2.0 no mods involved any way ive seeked help from another forum that actuly helped me and not confuse me like you have done to me
Title: Re: need little help changing this code to work with smf 2.0
Post by: Bulakbol on April 15, 2008, 01:38:38 AM
Sorry, I didn't mean to. Glad to know you found help from other site. Good luck.
Title: Re: need little help changing this code to work with smf 2.0
Post by: metallica48423 on April 17, 2008, 08:42:14 PM
There is no need to be rude, Johny was simply trying to help.

So you were able to correct the issue?

There are other parts of that query that would need to be updated to work with 2.0's database structure, as well as the actual query itself.  If you still require assistance with that, please let us know
Title: Re: need little help changing this code to work with smf 2.0
Post by: Bulakbol on April 18, 2008, 06:24:51 AM
 Thanks Metallica48423. I remember seeing the function from ArcadeStats.php so I thought it's the author's responsibility to update his/her mod.
Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 19, 2008, 04:12:03 AM
Quote from: metallica48423 on April 17, 2008, 08:42:14 PM
There is no need to be rude, Johny was simply trying to help.

So you were able to correct the issue?

There are other parts of that query that would need to be updated to work with 2.0's database structure, as well as the actual query itself.  If you still require assistance with that, please let us know

i wasnt being rude and im sry if i come accrosse that way im just fed up with asking for support and people dont read my question properly and get me confused as i stated befor this works with the latest arcade i just needed the db_query changed and mysql fect assoc as i can do it i get error so if some one can do ill will be a happy bunny there simple no mods involved and certqainly no auther needed apart from smf with help to change the mentiond above

here is my code

function ArcadeStats_BestPlayers($count = 10)
{
global $smcFunc;

$results = db_query("'
SELECT count(*) AS champions, IFNULL(mem.ID_MEMBER, 0) AS ID_MEMBER, IFNULL(mem.realName, '') AS realName, IFNULL(mem.avatar, '') AS avatar
FROM {$db_prefix}arcade_games AS game
LEFT JOIN {$db_prefix}members AS mem ON (mem.id_member = game.id_member_first)
WHERE id_score_first > 0
GROUP BY game.id_member_first
ORDER BY champions DESC 
LIMIT 0,$count", __FILE__, __LINE__);

$top = array();
$max = -1;

while ($score = mysql_fetch_assoc($results))
{
if ($max == -1)
$max = $score['champions'];

$top[] = array(
'name' => $score['member_name'],
'avatar' => $score['avatar'],
'link' => !empty($score['member_name']) ? '<a href="' . $scripturl . '?action=profile;u=' . $score['id_member'] . '">' .  $score['member_name'] . '</a>' : $txt['arcade_guest'],
'champions' => $score['champions'],
//'precent' => ($score['champions'] / $max) * 100,
);
}

if (count($top) == 0)
return false;
elseif ($count > 1)
return $top;
else
return $top[0];
}
$top_player = ArcadeStats_BestPlayers(10);
$i=0; //players position

//array for icons
$poz = array('/first.gif','/second.gif','/third.gif','/fourth.gif','/fifth.gif','/sixth.gif','/seventh.gif','/eigth.gif','/ninth.gif','/tenth.gif');

echo '
<table width="100%" border="0" cellpadding="1">
<tr>
<td class="titlebg" colspan="10"><div align="center"><b>Top 10 Arcade Champions</b></div></td></tr><tr></br></tr><tr>';
if($top_player != false)
{
foreach ($top_player as $row)

echo '

<td><div align="center"><img src="http://waynesworld.kicks-ass.net/forum/Themes/default/images/arc_icons',$poz[$i] , '"/><br/><br/>
<img src="http://waynesworld.kicks-ass.net/forum/avatars/', $row['avatar'],'"><br/>
',$row['link'],'<br/>
',$row['champions'],' </div></span></td>
';
$i++;
}

echo'</tr><tr></br></tr><tr></br></tr><tr></br></tr><tr></br></tr></table></div>';[code]


this is the error i get when i change

$results = db_query("'

to

$result = $smcFunc['db_query']('', '

and

while ($score = mysql_fetch_assoc($results))

to

while ($score = $smcFunc['db_fetch_assoc']($request))   

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\****\htdocs\champs.php on line 19

   
Title: Re: need little help changing this code to work with smf 2.0
Post by: metallica48423 on April 19, 2008, 05:01:01 AM
i'll have a look at it tomorrow -- part of it is going to need to be rewritten

*marks as unread*
Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 19, 2008, 05:11:35 AM
ok thanks i do appretiate it im getting to the point where im getting so stressed over but i dont like just giving up
Title: Re: need little help changing this code to work with smf 2.0
Post by: metallica48423 on April 20, 2008, 06:06:27 PM
Alright: give this a try:


<?php

function ArcadeStats_BestPlayers($count 10)
{
global 
$smcFunc;

$result $smcFunc['db_query'](''"
SELECT count(*) AS champions, IFNULL(mem.ID_MEMBER, 0) AS ID_MEMBER, IFNULL(mem.realName, '') AS realName, IFNULL(mem.avatar, '') AS avatar
FROM {db_prefix}arcade_games AS game
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = game.id_member_first)
WHERE id_score_first > 0
GROUP BY game.id_member_first
ORDER BY champions DESC 
LIMIT 0, {int:count}"
,
array(
'count' => $count,
)
 );

$top = array();
$max = -1;

while (
$score $smcFunc['db_fetch_assoc']($result))
{
if (
$max == -1)
$max $score['champions'];

$top[] = array(
'name' => $score['member_name'],
'avatar' => $score['avatar'],
'link' => !empty($score['member_name']) ? '<a href="' $scripturl '?action=profile;u=' $score['id_member'] . '">' .  $score['member_name'] . '</a>' $txt['arcade_guest'],
'champions' => $score['champions'],
//'precent' => ($score['champions'] / $max) * 100,
);
}

if (
count($top) == 0)
return 
false;
elseif (
$count 1)
return 
$top;
else
return 
$top[0];
}
$top_player ArcadeStats_BestPlayers(10);
$i=0//players position

//array for icons
$poz = array('/first.gif','/second.gif','/third.gif','/fourth.gif','/fifth.gif','/sixth.gif','/seventh.gif','/eigth.gif','/ninth.gif','/tenth.gif');

echo 
'
<table width="100%" border="0" cellpadding="1">
<tr>
<td class="titlebg" colspan="10"><div align="center"><b>Top 10 Arcade Champions</b></div></td></tr><tr></br></tr><tr>'
;
if(
$top_player != false)
{
foreach (
$top_player as $row)

echo 
'

<td><div align="center"><img src="http://waynesworld.kicks-ass.net/forum/Themes/default/images/arc_icons'
,$poz[$i] , '"/><br/><br/>
<img src="http://waynesworld.kicks-ass.net/forum/avatars/'
$row['avatar'],'"><br/>
'
,$row['link'],'<br/>
'
,$row['champions'],' </div></span></td>
'
;
$i++;
}

echo
'</tr><tr></br></tr><tr></br></tr><tr></br></tr><tr></br></tr></table></div>';

?>

Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 20, 2008, 06:12:34 PM
that gives this error

Database Error
Please try again. If you come back to this error screen, report the error to an administrator


thanks for for helping me
Title: Re: need little help changing this code to work with smf 2.0
Post by: metallica48423 on April 20, 2008, 06:19:25 PM
can you look in the error logs and see if they provide more information about the errors?
Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 20, 2008, 06:36:35 PM
here the error from the logs

http://waynesworld.kicks-ass.net/forum/index.php?http://waynesworld.kicks-ass.net/champs.php 
Database Error: Unknown column 'mem.realName' in 'field list'
File: C:/****/htdocs/champs.php
Line: 29 

   Guest   Today at 10:09:33 pm 
82.43.83.106     3cea2ca62c585027270d6fc870687531 
   Type of error: Database 
http://waynesworld.kicks-ass.net/forum/index.php?http://waynesworld.kicks-ass.net/champs.php 
Database Error: Unknown column 'mem.realName' in 'field list'
File: C:/****/htdocs/champs.php
Line: 29 

   wdm2005   April 14, 2008, 04:55:30 am 
82.43.83.106     6c447dc181614c525288757f6d6f053f 
   Type of error: Database 
http://waynesworld.kicks-ass.net/forum/index.php?http://waynesworld.kicks-ass.net/champs.php 
Database Error: 
File: C:/****/htdocs/champs.php
Line: 25 

   wdm2005   April 14, 2008, 04:50:17 am 
82.43.83.106     6c447dc181614c525288757f6d6f053f 
   Type of error: Database 
http://waynesworld.kicks-ass.net/forum/index.php?http://waynesworld.kicks-ass.net/champs.php 
Database Error: 
File: C:/****/htdocs/champs.php
Line: 25 

   wdm2005   April 14, 2008, 04:48:04 am 
82.43.83.106     6c447dc181614c525288757f6d6f053f 
   Type of error: Database 
http://waynesworld.kicks-ass.net/forum/index.php?http://waynesworld.kicks-ass.net/champs.php 
Database Error: 
File: C:/****/htdocs/champs.php
Line: 25 

   wdm2005   April 14, 2008, 04:48:02 am 
82.43.83.106     6c447dc181614c525288757f6d6f053f 
   Type of error: Database 
http://waynesworld.kicks-ass.net/forum/index.php?http://waynesworld.kicks-ass.net/champs.php 
Database Error: 
File: C:/****/htdocs/champs.php
Line: 25 

   wdm2005   April 14, 2008, 04:47:38 am 
82.43.83.106     6c447dc181614c525288757f6d6f053f 
   Type of error: Database 
http://waynesworld.kicks-ass.net/forum/index.php?http://waynesworld.kicks-ass.net/champs.php 
Database Error: 
File: C:/****/htdocs/champs.php
Line: 25 

Title: Re: need little help changing this code to work with smf 2.0
Post by: metallica48423 on April 20, 2008, 09:21:58 PM
Ahh... i neglected to actually rewrite the query part of the query... my apoligies :P

I'll look at it again and post again when i'm done
Title: Re: need little help changing this code to work with smf 2.0
Post by: metallica48423 on April 20, 2008, 09:24:53 PM
Okay, try this


<?php

function ArcadeStats_BestPlayers($count 10)
{
global 
$smcFunc;

$result $smcFunc['db_query'](''"
SELECT count(*) AS champions, IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, '') AS real_name, IFNULL(mem.avatar, '') AS avatar
FROM {db_prefix}arcade_games AS game
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = game.id_member_first)
WHERE id_score_first > 0
GROUP BY game.id_member_first
ORDER BY champions DESC 
LIMIT 0, {int:count}"
,
array(
'count' => $count,
)
 );

$top = array();
$max = -1;

while (
$score $smcFunc['db_fetch_assoc']($result))
{
if (
$max == -1)
$max $score['champions'];

$top[] = array(
'name' => $score['member_name'],
'avatar' => $score['avatar'],
'link' => !empty($score['member_name']) ? '<a href="' $scripturl '?action=profile;u=' $score['id_member'] . '">' .  $score['member_name'] . '</a>' $txt['arcade_guest'],
'champions' => $score['champions'],
//'precent' => ($score['champions'] / $max) * 100,
);
}

if (
count($top) == 0)
return 
false;
elseif (
$count 1)
return 
$top;
else
return 
$top[0];
}
$top_player ArcadeStats_BestPlayers(10);
$i=0//players position

//array for icons
$poz = array('/first.gif','/second.gif','/third.gif','/fourth.gif','/fifth.gif','/sixth.gif','/seventh.gif','/eigth.gif','/ninth.gif','/tenth.gif');

echo 
'
<table width="100%" border="0" cellpadding="1">
<tr>
<td class="titlebg" colspan="10"><div align="center"><b>Top 10 Arcade Champions</b></div></td></tr><tr></br></tr><tr>'
;
if(
$top_player != false)
{
foreach (
$top_player as $row)

echo 
'

<td><div align="center"><img src="http://waynesworld.kicks-ass.net/forum/Themes/default/images/arc_icons'
,$poz[$i] , '"/><br/><br/>
<img src="http://waynesworld.kicks-ass.net/forum/avatars/'
$row['avatar'],'"><br/>
'
,$row['link'],'<br/>
'
,$row['champions'],' </div></span></td>
'
;
$i++;
}

echo
'</tr><tr></br></tr><tr></br></tr><tr></br></tr><tr></br></tr></table></div>';

?>


Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 21, 2008, 12:26:46 AM
ok that got it but its not showing the nameit shows the avatar and ammount of wins but no name

see here

http://waynesworld.kicks-ass.net/champs.php
Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 21, 2008, 12:32:41 AM
topic solved thank you metalica
Title: Re: need little help changing this code to work with smf 2.0
Post by: metallica48423 on April 21, 2008, 12:45:39 AM
can I ask what you changed that fixed it? just for my own info :P
Title: Re: need little help changing this code to work with smf 2.0
Post by: SA™ on April 21, 2008, 12:49:57 AM
i changed this

real_name

to

member_name