Author |
Message |
CodyG
Life Cycles Becoming CPU Cycles
![](modules/Forums/images/avatars/186c8977515afcc3ed82a.jpg)
Joined: Jan 02, 2003
Posts: 714
Location: Vancouver Island
|
Posted:
Fri Jan 05, 2007 6:54 pm |
|
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 |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Gremmie
Former Moderator in Good Standing
![](modules/Forums/images/avatars/0cd76dcf45da5de2cf864.jpg)
Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA
|
Posted:
Fri Jan 05, 2007 7:26 pm |
|
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. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Gremmie
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Fri Jan 05, 2007 7:48 pm |
|
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"]);
}
|
|
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
CodyG
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Fri Jan 05, 2007 8:24 pm |
|
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)"]);
}
?>
|
|
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Gremmie
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Fri Jan 05, 2007 11:07 pm |
|
Try $grow[2]
You might also just do a print_r($grow); to see what it has in it. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
evaders99
Former Moderator in Good Standing
![](modules/Forums/images/avatars/803d73f6452557b947721.jpg)
Joined: Apr 30, 2004
Posts: 3221
|
Posted:
Sat Jan 06, 2007 1:27 am |
|
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! |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
CodyG
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sat Jan 06, 2007 7:34 am |
|
Perfect! I learn something new everyday.
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. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Gremmie
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sat Jan 06, 2007 5:24 pm |
|
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. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
|