Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
CodyG
Life Cycles Becoming CPU Cycles



Joined: Jan 02, 2003
Posts: 714
Location: Vancouver Island

PostPosted: Fri Jan 05, 2007 6:54 pm Reply with quote

I'm trying to create a block and using some code from another module. I'm not sure if the $content is in the right place. Or perhaps it is something else. The error... no errors, just blank from where the the block should be.

Any ideas why this is not working?

Code:
<?php

if (eregi("block-alltimegames.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}


$result = mysql_query("SELECT gamename, playername, max( playerscore )FROM `nuke_flashgames_hiscores_alltime`GROUP BY gamename LIMIT 0 , 30);
while ($grow = mysql_fetch_array($result)) {
$content = "<table border=\"0\" width=\"125px\"><tr><td><p align=\"center\"All Time<br />High Scores<br /></td></tr><tr><td><b>%s</b><br />%s<br />%s<br /></td></tr></table>",
$grow["gamename"], $grow["playername"], $grow["playerscore"];

}


?>

_________________
"We want to see if life is ubiquitous." D.Goldin

Last edited by CodyG on Sat Jan 06, 2007 7:35 am; edited 1 time in total 
View user's profile Send private message
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Fri Jan 05, 2007 7:26 pm Reply with quote

Well for starters, I see an unterminated string constant.

$result = mysql_query("SELECT gamename, playername, max( playerscore )FROM `nuke_flashgames_hiscores_alltime`GROUP BY gamename LIMIT 0 , 30");

Add the " I highlighted in bold red.
 
View user's profile Send private message
Gremmie







PostPosted: Fri Jan 05, 2007 7:48 pm Reply with quote

And then change this

Code:


while ($grow = mysql_fetch_array($result)) {
$content = "<table border=\"0\" width=\"125px\"><tr><td><p align=\"center\"All Time<br />High Scores<br /></td></tr><tr><td><b>%s</b><br />%s<br />%s<br /></td></tr></table>",
$grow["gamename"], $grow["playername"], $grow["playerscore"];
}


To this:
Code:


$content = '';
while ($grow = mysql_fetch_array($result)) {
$content .= sprintf("<table border=\"0\" width=\"125px\"><tr><td><p align=\"center\">All Time<br />High Scores<br /></p></td></tr><tr><td><b>%s</b><br />%s<br />%s<br /></td></tr></table>",
   $grow["gamename"], $grow["playername"], $grow["playerscore"]);
}
 
CodyG







PostPosted: Fri Jan 05, 2007 8:24 pm Reply with quote

Thank you for your help Gremmie ...
I made a change or two and now the block is displaying the gamename and the playername, as it should, but it isn't showing the actual scores.
In the last line I tried $grow["max(playerscore)"] and $grow["playerscore"] but both vars turn up a blank.

Code:
<?php

if (eregi("block-alltimegames.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}

$result = mysql_query("SELECT gamename, playername, max( playerscore ) FROM `nuke_flashgames_hiscores_alltime`GROUP BY gamename LIMIT 0 , 30");
$content = '';
while ($grow = mysql_fetch_array($result)) {
$content .= sprintf("<table border=\"0\" width=\"125px\"><tr><td></td></tr><tr><td><b>%s</b><br />%s<br />%s<br /></td></tr></table>",
   $grow["gamename"], $grow["playername"], $grow["max(playerscore)"]);
}

?>
 
Gremmie







PostPosted: Fri Jan 05, 2007 11:07 pm Reply with quote

Try $grow[2]

You might also just do a print_r($grow); to see what it has in it.
 
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Sat Jan 06, 2007 1:27 am Reply with quote

You'll need to give max( playerscore ) an alias
Code:


max( playerscore ) as playerscoremax


And then you can reference it by name as
Code:


$grow['playerscoremax']

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
CodyG







PostPosted: Sat Jan 06, 2007 7:34 am Reply with quote

Perfect! I learn something new everyday. Wink
Here is my final code.

Code:
<?php

if (eregi("block-alltimegames.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}


$result = mysql_query("SELECT gamename, playername, max( playerscore )as playerscore FROM `nuke_flashgames_hiscores_alltime`GROUP BY gamename LIMIT 0 , 10");
$content = '';
while ($grow = mysql_fetch_array($result)) {
$content .= sprintf("<br /><b>%s</b><br />%s<br />%s",
   $grow["gamename"], $grow["playername"], $grow["playerscore"]);
}

?>


Thank you and Have a happy nuking day.
 
Gremmie







PostPosted: Sat Jan 06, 2007 5:24 pm Reply with quote

Ah, good one evaders. As I recall, on my XAMPP system with MySQL 5.0, the column will show up in PHP just like you had it in the query. But my "real" host (which uses MySQL 4 something) I had to use an integer index to get the column.

But the alias is the way to go.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©