Josh Barton
asked on
correcting a bug or two in a list sorter
i have tried and tried but i cannot figure out whats wrong with this:
----------playerlist.php
<html>
<head>
</head>
<body bgcolor="#000000" text="#FFFFFF">
<?php
$self = "playerlist.php";
if (!$sortby) {
$sortby = "strength";
}
$query= "SELECT `username` , `password` , `email` , `gold` , `hp` , `strength` , `level` , `exp` , `pos` , `special` , `date` , `sentence` , `map` , `ca` , `weapondmg` , `initiative` , `land` , `ann1` , `ann2` , `ann3` , `totalhp` , `defmonst` FROM `users` WHERE 1 ORDER BY `strength` DESC";
$result = mysql_query($query, $db) or die ("SQL error in query '$query' : ".mysql_error());
$num_rows = mysql_numrows($result);
?>
<script language="JavaScript">
function openDir( form ) {
var newIndex = jumpmenu.sortmenu.selected Index;
if ( newIndex == 0 ) {
alert( "Please select a location!" );
} else {
cururl = jumpmenu.sortmenu.options[ newIndex ].value;
window.location.assign( cururl );
}
}
</script>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF">
<tr>
<td background="images/top.jpg "><img src="images/corner.jpg" width="10" height="10"></td>
<td background="images/top.jpg " bgcolor="#000000"> <div align="center"> </div></td>
<td background="images/top.jpg " bgcolor="#000000"><img src="images/corner.jpg" width="10" height="10"></td>
</tr>
<tr>
<td width="1%" background="images/side.jp g" bgcolor="#000000"></td>
<td width="620" height="280" valign="top" bgcolor="#000000"><p align="left"><img src="images/playlist.jpg" width="197" height="50"></p>
<table width="293" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="131">Sorting Method:</td>
<td width="162"><form name="jumpmenu" method="post" action="">
<select name="sortmenu" onChange="openDir( this.sortmenu )">
<option value="<?php echo "$self"."?"."sortby=streng th"; ?>" selected>By Most Powerful</option>
<option value="<?php echo "$self"."?"."sortby=gold"; ?>">By Most Gold</option>
<option value="<?php echo "$self"."?"."sortby=level" ; ?>">By Highest Level</option>
<option value="<?php echo "$self"."?"."sortby=exp"; ?>">By Most XP</option>
</select>
</form></td>
</tr>
</table>
<?php
include('connect.php');
while ($rankingfield=mysql_fetch _array($re sult)) {
$player_name = $rankingfield[0];
$player_gold = $rankingfield[3];
$player_strength = $rankingfield[5];
$player_exp = $rankingfield[7];
$player_lvl = $rankingfield[6];
$date_log = $rankingfield[10];
switch ($sortby) {
case "strength":
$sorted_data = $player_strength;
$sort_label ="Strength";
break;
case "gold":
$sorted_data = $player_gold;
$sort_label ="Gold";
break;
case "level":
$sorted_data = $player_lvl;
$sort_label ="Level";
break;
case "exp":
$sorted_data = $player_exp;
$sort_label ="Experience";
break;
}
?>
<table width="593" border="0" align="left" cellpadding="0" cellspacing="1">
<tr bgcolor="#B9CDD9">
<th width="270" height="16" bgcolor="#000000"><div align="left"><font size="2" face="Geneva, Arial, Helvetica, sans-serif">Users</font></ div></th>
<th width="159" bgcolor="#000000"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo "Sorted by: "."$sortlabel"; ?></font></th>
<th width="218" bgcolor="#000000"><div align="left">Date last Logged
in</div></th>
</tr>
<?php
/*
echo <<<EOS
<tr>
<td height=19 bgcolor="#000000">$player_ name</td>
<td height=19 bgcolor="#000000">$sorted_ data</td>
<td height=19 bgcolor="#000000">$date_lo g</td>
</tr>
EOS;
*/
}
?>
</table> </td>
<td width="1%" background="images/side.jp g" bgcolor="#000000"></td>
</tr>
<tr>
<td background="images/top.jpg "><img src="images/corner.jpg" width="10" height="10"></td>
<td height="1%" background="images/top.jpg " bgcolor="#000000"></td>
<td background="images/top.jpg " bgcolor="#000000"><img src="images/corner.jpg" width="10" height="10"></td>
</tr>
</table>
----------playerlist.php
<html>
<head>
</head>
<body bgcolor="#000000" text="#FFFFFF">
<?php
$self = "playerlist.php";
if (!$sortby) {
$sortby = "strength";
}
$query= "SELECT `username` , `password` , `email` , `gold` , `hp` , `strength` , `level` , `exp` , `pos` , `special` , `date` , `sentence` , `map` , `ca` , `weapondmg` , `initiative` , `land` , `ann1` , `ann2` , `ann3` , `totalhp` , `defmonst` FROM `users` WHERE 1 ORDER BY `strength` DESC";
$result = mysql_query($query, $db) or die ("SQL error in query '$query' : ".mysql_error());
$num_rows = mysql_numrows($result);
?>
<script language="JavaScript">
function openDir( form ) {
var newIndex = jumpmenu.sortmenu.selected
if ( newIndex == 0 ) {
alert( "Please select a location!" );
} else {
cururl = jumpmenu.sortmenu.options[
window.location.assign( cururl );
}
}
</script>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF">
<tr>
<td background="images/top.jpg
<td background="images/top.jpg
<td background="images/top.jpg
</tr>
<tr>
<td width="1%" background="images/side.jp
<td width="620" height="280" valign="top" bgcolor="#000000"><p align="left"><img src="images/playlist.jpg" width="197" height="50"></p>
<table width="293" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="131">Sorting Method:</td>
<td width="162"><form name="jumpmenu" method="post" action="">
<select name="sortmenu" onChange="openDir( this.sortmenu )">
<option value="<?php echo "$self"."?"."sortby=streng
<option value="<?php echo "$self"."?"."sortby=gold";
<option value="<?php echo "$self"."?"."sortby=level"
<option value="<?php echo "$self"."?"."sortby=exp"; ?>">By Most XP</option>
</select>
</form></td>
</tr>
</table>
<?php
include('connect.php');
while ($rankingfield=mysql_fetch
$player_name = $rankingfield[0];
$player_gold = $rankingfield[3];
$player_strength = $rankingfield[5];
$player_exp = $rankingfield[7];
$player_lvl = $rankingfield[6];
$date_log = $rankingfield[10];
switch ($sortby) {
case "strength":
$sorted_data = $player_strength;
$sort_label ="Strength";
break;
case "gold":
$sorted_data = $player_gold;
$sort_label ="Gold";
break;
case "level":
$sorted_data = $player_lvl;
$sort_label ="Level";
break;
case "exp":
$sorted_data = $player_exp;
$sort_label ="Experience";
break;
}
?>
<table width="593" border="0" align="left" cellpadding="0" cellspacing="1">
<tr bgcolor="#B9CDD9">
<th width="270" height="16" bgcolor="#000000"><div align="left"><font size="2" face="Geneva, Arial, Helvetica, sans-serif">Users</font></
<th width="159" bgcolor="#000000"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo "Sorted by: "."$sortlabel"; ?></font></th>
<th width="218" bgcolor="#000000"><div align="left">Date last Logged
in</div></th>
</tr>
<?php
/*
echo <<<EOS
<tr>
<td height=19 bgcolor="#000000">$player_
<td height=19 bgcolor="#000000">$sorted_
<td height=19 bgcolor="#000000">$date_lo
</tr>
EOS;
*/
}
?>
</table> </td>
<td width="1%" background="images/side.jp
</tr>
<tr>
<td background="images/top.jpg
<td height="1%" background="images/top.jpg
<td background="images/top.jpg
</tr>
</table>
What error are you getting?
ASKER
SQL error in query 'SELECT `username` , `password` , `email` , `gold` , `hp` , `strength` , `level` , `exp` , `pos` , `special` , `date` , `sentence` , `map` , `ca` , `weapondmg` , `initiative` , `land` , `ann1` , `ann2` , `ann3` , `totalhp` , `defmonst` FROM `users` WHERE 1 ORDER BY `strength` DESC' :
What is the MySQL error you're getting?
Try this and tell me what you get:
$result = mysql_query($query, $db) or die (mysql_error());
Try this and tell me what you get:
$result = mysql_query($query, $db) or die (mysql_error());
Try getting rid of "WHERE 1"
ASKER
it still does it
i did try this:
$result = mysql_query($query, $db) or die (mysql_error());
thats how i got the error message
i did try this:
$result = mysql_query($query, $db) or die (mysql_error());
thats how i got the error message
You didn't give me the mysql error message. you gave me your custom error message. you most likely have a column mis-named. run that line of code as i have written it above, and tell me the actual mysql_error message that you get.
ASKER
the mysql statement is used was generated by phpmyadmin so i dont think the columsn are misnamed
And you still haven't displayed the mysql_error() message!
You noticed you haven't got any mysql_connect or mysql_select_db statement in your code so it would be quite logical to have an error while querying a db you aren't connected to.
-r-
-r-
ASKER
ok i figured out the problem and i added some more code but why wont the page load, its just blank
-------------------------- ---------- -www.j-barton.com/antioch/playerlist.php
<html>
<head>
</head>
<body bgcolor="#000000" text="#FFFFFF">
<?php
include('connect.php');
$self = "playerlist.php";
if (!$sortby) {
$sortby = "strength";
}
?>
<script language="JavaScript">
function openDir( form ) {
var newIndex = jumpmenu.sortmenu.selected Index;
if ( newIndex == 0 ) {
alert( "Please select a location!" );
} else {
cururl = jumpmenu.sortmenu.options[ newIndex ].value;
window.location.assign( cururl );
}
}
</script>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF">
<tr>
<td background="images/top.jpg "><img src="images/corner.jpg" width="10" height="10"></td>
<td background="images/top.jpg " bgcolor="#000000"> <div align="center"> </div></td>
<td background="images/top.jpg " bgcolor="#000000"><img src="images/corner.jpg" width="10" height="10"></td>
</tr>
<tr>
<td width="1%" background="images/side.jp g" bgcolor="#000000"></td>
<td width="620" height="280" valign="top" bgcolor="#000000"><p align="left"><img src="images/playlist.jpg" width="197" height="50"></p>
<table width="293" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="131">Sorting Method:</td>
<td width="162"><form name="jumpmenu" method="post" action="">
<select name="sortmenu" onChange="openDir( this.sortmenu )">
<option value="<?php echo "$self"."?"."sortby=streng th"; ?>" selected>By Most Powerful</option>
<option value="<?php echo "$self"."?"."sortby=gold"; ?>">By Most Gold</option>
<option value="<?php echo "$self"."?"."sortby=level" ; ?>">By Highest Level</option>
<option value="<?php echo "$self"."?"."sortby=exp"; ?>">By Most XP</option>
</select>
</form></td>
</tr>
</table>
<?php
switch ($sortby) {
case "strength":
$sorted_data = $player_strength;
$sort_label ="Strength";
break;
case "gold":
$sorted_data = $player_gold;
$sort_label ="Gold";
break;
case "level":
$sorted_data = $player_lvl;
$sort_label ="Level";
break;
case "exp":
$sorted_data = $player_exp;
$sort_label ="Experience";
break;
}
?>
<table width="593" border="0" align="left" cellpadding="0" cellspacing="1">
<tr bgcolor="#B9CDD9">
<th width="270" height="16" bgcolor="#000000"><div align="left"><font size="2" face="Geneva, Arial, Helvetica, sans-serif">Users</font></ div></th>
<th width="159" bgcolor="#000000"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo "Sorted by: "."$sortlabel"; ?></font></th>
<th width="218" bgcolor="#000000"><div align="left">Date last Logged
in</div></th>
</tr>
<?php
$query= "SELECT username, strength, date, exp, level, gold FROM users ORDER BY `$sortby` DESC";
$result = mysql_query($query, $db) or die ("SQL error in query '$query' : ".mysql_error());
$num_rows = mysql_numrows($result);
while(list($player_name, $player_strength, $date_log, $player_exp, $player_lvl, $player_gold) = mysql_fetch_array($result) ) {
}
echo <<<EOS
<tr>
<td height=19 bgcolor="#000000">$player_ name</td>
<td height=19 bgcolor="#000000">$sorted_ data</td>
<td height=19 bgcolor="#000000">$date_lo g</td>
</tr>
EOS;
}
?>
</table> </td>
<td width="1%" background="images/side.jp g" bgcolor="#000000"></td>
</tr>
<tr>
<td background="images/top.jpg "><img src="images/corner.jpg" width="10" height="10"></td>
<td height="1%" background="images/top.jpg " bgcolor="#000000"></td>
<td background="images/top.jpg " bgcolor="#000000"><img src="images/corner.jpg" width="10" height="10"></td>
</tr>
</table>
ive raised the points as this is a harder question
--------------------------
<html>
<head>
</head>
<body bgcolor="#000000" text="#FFFFFF">
<?php
include('connect.php');
$self = "playerlist.php";
if (!$sortby) {
$sortby = "strength";
}
?>
<script language="JavaScript">
function openDir( form ) {
var newIndex = jumpmenu.sortmenu.selected
if ( newIndex == 0 ) {
alert( "Please select a location!" );
} else {
cururl = jumpmenu.sortmenu.options[
window.location.assign( cururl );
}
}
</script>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF">
<tr>
<td background="images/top.jpg
<td background="images/top.jpg
<td background="images/top.jpg
</tr>
<tr>
<td width="1%" background="images/side.jp
<td width="620" height="280" valign="top" bgcolor="#000000"><p align="left"><img src="images/playlist.jpg" width="197" height="50"></p>
<table width="293" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="131">Sorting Method:</td>
<td width="162"><form name="jumpmenu" method="post" action="">
<select name="sortmenu" onChange="openDir( this.sortmenu )">
<option value="<?php echo "$self"."?"."sortby=streng
<option value="<?php echo "$self"."?"."sortby=gold";
<option value="<?php echo "$self"."?"."sortby=level"
<option value="<?php echo "$self"."?"."sortby=exp"; ?>">By Most XP</option>
</select>
</form></td>
</tr>
</table>
<?php
switch ($sortby) {
case "strength":
$sorted_data = $player_strength;
$sort_label ="Strength";
break;
case "gold":
$sorted_data = $player_gold;
$sort_label ="Gold";
break;
case "level":
$sorted_data = $player_lvl;
$sort_label ="Level";
break;
case "exp":
$sorted_data = $player_exp;
$sort_label ="Experience";
break;
}
?>
<table width="593" border="0" align="left" cellpadding="0" cellspacing="1">
<tr bgcolor="#B9CDD9">
<th width="270" height="16" bgcolor="#000000"><div align="left"><font size="2" face="Geneva, Arial, Helvetica, sans-serif">Users</font></
<th width="159" bgcolor="#000000"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo "Sorted by: "."$sortlabel"; ?></font></th>
<th width="218" bgcolor="#000000"><div align="left">Date last Logged
in</div></th>
</tr>
<?php
$query= "SELECT username, strength, date, exp, level, gold FROM users ORDER BY `$sortby` DESC";
$result = mysql_query($query, $db) or die ("SQL error in query '$query' : ".mysql_error());
$num_rows = mysql_numrows($result);
while(list($player_name, $player_strength, $date_log, $player_exp, $player_lvl, $player_gold) = mysql_fetch_array($result)
}
echo <<<EOS
<tr>
<td height=19 bgcolor="#000000">$player_
<td height=19 bgcolor="#000000">$sorted_
<td height=19 bgcolor="#000000">$date_lo
</tr>
EOS;
}
?>
</table> </td>
<td width="1%" background="images/side.jp
</tr>
<tr>
<td background="images/top.jpg
<td height="1%" background="images/top.jpg
<td background="images/top.jpg
</tr>
</table>
ive raised the points as this is a harder question
You should add the line below to the top of your code:
<?php error_reporting(E_ALL); ?>
There might be numerous problems for example
if (!$sortby) {
$sortby = "strength";
}
should/could be
if(!isset($_GET['sortby']) )
$sortby = 'strength';
else
$sortby = $_GET['sortby'];
And there might be more problems popping to the surface.
-r-
<?php error_reporting(E_ALL); ?>
There might be numerous problems for example
if (!$sortby) {
$sortby = "strength";
}
should/could be
if(!isset($_GET['sortby'])
$sortby = 'strength';
else
$sortby = $_GET['sortby'];
And there might be more problems popping to the surface.
-r-
In this part:
===============
while(list($player_name, $player_strength, $date_log, $player_exp, $player_lvl, $player_gold) = mysql_fetch_array($result) ) {
}
echo <<<EOS
<tr>
<td height=19 bgcolor="#000000">$player_ name</td>
<td height=19 bgcolor="#000000">$sorted_ data</td>
<td height=19 bgcolor="#000000">$date_lo g</td>
</tr>
EOS;
======================
THE echo seems to be OUTSIDE of the While Loop.
Try it like this
while(list($player_name, $player_strength, $date_log, $player_exp, $player_lvl, $player_gold) = mysql_fetch_array($result) )
{
echo <<<EOS
<tr>
<td height=19 bgcolor="#000000">$player_ name</td>
<td height=19 bgcolor="#000000">$sorted_ data</td>
<td height=19 bgcolor="#000000">$date_lo g</td>
</tr>
EOS;
}
===============
while(list($player_name, $player_strength, $date_log, $player_exp, $player_lvl, $player_gold) = mysql_fetch_array($result)
}
echo <<<EOS
<tr>
<td height=19 bgcolor="#000000">$player_
<td height=19 bgcolor="#000000">$sorted_
<td height=19 bgcolor="#000000">$date_lo
</tr>
EOS;
======================
THE echo seems to be OUTSIDE of the While Loop.
Try it like this
while(list($player_name, $player_strength, $date_log, $player_exp, $player_lvl, $player_gold) = mysql_fetch_array($result)
{
echo <<<EOS
<tr>
<td height=19 bgcolor="#000000">$player_
<td height=19 bgcolor="#000000">$sorted_
<td height=19 bgcolor="#000000">$date_lo
</tr>
EOS;
}
ASKER
still just a blank page, i tried the isset i tried the error reporting i tried moving the bracket and it still doesnt work, what could it be, im adding 10 points
what is the value of mysql_numrows($result); ?
try
while($Data = mysql_fetch_array($Result) )
{
echo '<tr>
<td height=19 bgcolor="#000000">'.$Data[ "player_na me"].'</td >
<td height=19 bgcolor="#000000">'.$Data[ $sorted_da ta].'</td>
<td height=19 bgcolor="#000000">'.$Data[ "date_log" ].'</td>
</tr>';
}
while($Data = mysql_fetch_array($Result)
{
echo '<tr>
<td height=19 bgcolor="#000000">'.$Data[
<td height=19 bgcolor="#000000">'.$Data[
<td height=19 bgcolor="#000000">'.$Data[
</tr>';
}
ASKER
can somebody rewrite the thing, there must be some other bug were missing, may as try some other way
thanks
thanks
since it still displays a white page I guess there is an error but it doesnt show up.
Try enabling error display by setting the following in your PHP.ini
display_errors = On
or
ini_set("display_errors"," On");
in your script
Try enabling error display by setting the following in your PHP.ini
display_errors = On
or
ini_set("display_errors","
in your script
@TheClickMarser
That's exeactly the purpose of error_reporting(E_ALL);, but in my opinion the error_reporting function goes over the ini_set thingies, like every build in function goes over ini_set for that matter.
-r-
That's exeactly the purpose of error_reporting(E_ALL);, but in my opinion the error_reporting function goes over the ini_set thingies, like every build in function goes over ini_set for that matter.
-r-
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks, it works great!!, only one problem I get an error when trying to select sort by most powerful in the jumpmenu, it only happens after you have already chosen one sorting method.