Jump to content

Array Problem


Joshua F

Recommended Posts

I am trying to make highscores for a game, and am having problems echoing out the information with arrays.

 

<?php
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM highscores_skills"),0) or die(mysql_error());
$offset = (isset($_GET["rank"]) && is_numeric($_GET["rank"]) && $_GET["rank"] < $count) ? $_GET["rank"] : 0;
//echo $offset;
//echo "SELECT * FROM highscores_skills ORDER BY ".getTable($_GET['table'])."LVL desc, ".getTable($_GET['table'])."XP desc LIMIT $offset, ".($offset + 21).";";
$row = mysql_query("SELECT * FROM highscores_skills ORDER BY ".getTable($_GET['table'])."LVL desc, ".getTable($_GET['table'])."XP desc LIMIT $offset, ".($offset + 21)."") or die (mysql_error());
while($query = mysql_fetch_assoc($row)) {
	$usernames[] = $query['username'];
	$levels[] = $query[''.getTable($_GET['table']).'LVL'];
	$exps[] = $query[''.getTable($_GET['table']).'XP'];
}
?>

That code as you can see is how it gets the information and such.

 

	
<?php
if($_GET['rank'] == 0 || $_GET['rank'] == null){
$rank = 1;
} else {
$rank = $_GET['rank'];
}

for($i = $rank; $i < ($rank + 21); $i++) {
	if($i > $count){
	} else {
		echo '<a href="personal.ws?user1='.$usernames[$i].'">'.ucWords($usernames[$i]).'</a><br/>';
	}
}
?>

That is an example code for listing the usernames.

 

My problem is that it'll show all of the correct information, until I get to about rank 990.

 

If you need a live preview I could post the link if needed.

Link to comment
Share on other sites

<?php
ob_start();
session_start();
@require('../system/connect.php');
include('../system/functions/hiscores.php');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:IE>

<head>
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
<title><?php getSitename(); ?></title>
<link href="../img/favicon.ico" rel="shortcut icon">
<link href="../css/basic-3.css" rel="stylesheet" type="text/css" media="all" />
<link href="../css/hiscores-1.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body style="background-image:url('../img/backgrounds/bg-<?php getBackground(); ?>.jpg');">
	<div id="body">

	<?php userBar('hiscores','index.ws'); ?><br />			<center>
			<div id="hiscoretitlebground">
				<div class="frame e">
					<b><?php getSitename(); ?> Hiscores</b><br />
					<a href="title.ws">Main Menu</a>
				</div>
			</div>
		</center><br />
<?php
if($_GET['table'] == null || $_GET['table'] == '' || ($_GET['table'] < 0 || $_GET['table'] >= 24)){
header('location: ?table=0');
}
if($_GET['rank'] && !is_numeric($_GET['rank'])){
header('location: ?table=0&rank=1');
} elseif($_GET['rank'] == null){
$_GET['rank'] = 0;
} elseif($_GET['rank'] < 1){
$_GET['rank'] = 0;
}
?>
		<table border="0" cellpadding="4" cellspacing="0">
			<tr>
				<td width="175" valign="top" align="left">
					<table cellpadding="0" cellspacing="0" style="line-height:5mm" border=0>
						<tr>
							<td width="5"></td>
							<td width="25"></td>
							<td width="95"></td>
						</tr>
						<tr>
							<td> </td>
							<td></td>
							<td align="left">
								<a href="index.ws?table=0">Overall</a>
							</td>
						</tr>
						<tr>
							<td> </td>
							<td>
								<img class="miniimg" src="../img/hiscores/skill_icon_attack1.gif" />
							</td>
							<td align="left">
								<a href="index.ws?table=1">Attack</a>
							</td>
						</tr>
						<tr>
							<td> </td>
							<td>
								<img class="miniimg" src="../img/hiscores/skill_icon_defence1.gif" />
							</td>
							<td align="left">
								<a href="index.ws?table=2">Defence</a>
							</td>
						</tr>
						<tr>
							<td> </td>
							<td>
								<img class="miniimg" src="../img/hiscores/skill_icon_strength1.gif" />
							</td>
							<td align="left">
								<a href="index.ws?table=3">Strength</a>
							</td>
						</tr>
						<tr>
							<td> </td>
							<td>
								<img class="miniimg" src="../img/hiscores/skill_icon_hitpoints1.gif" />
							</td>
							<td align="left">
								<a href="hiscores44a4.html?table=4">Hitpoints</a>
							</td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_ranged1.gif"></td>
						<td align="left"><a href="hiscores3e94.html?table=5">
						Ranged
						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_prayer1.gif"></td>
						<td align="left"><a href="hiscorese2db.html?table=6">
						Prayer
						</a></td>

						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_magic1.gif"></td>
						<td align="left"><a href="hiscoresbb44.html?table=7">
						Magic
						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_cooking1.gif"></td>
						<td align="left"><a href="hiscores5534.html?table=8">
						Cooking
						</a></td>
						</tr>
						<tr>
						<td> </td>

						<td><img class="miniimg" src="../img/hiscores/skill_icon_woodcutting1.gif"></td>
						<td align="left"><a href="hiscoresf851.html?table=9">
						Woodcutting
						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_fletching1.gif"></td>
						<td align="left"><a href="hiscores683a.html?table=10">
						Fletching
						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_fishing1.gif"></td>
						<td align="left"><a href="hiscores8127.html?table=11">
						Fishing

						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_firemaking1.gif"></td>
						<td align="left"><a href="hiscores7a05.html?table=12">
						Firemaking
						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_crafting1.gif"></td>
						<td align="left"><a href="hiscoresb405.html?table=13">
						Crafting
						</a></td>
						</tr>
						<tr>

						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_smithing1.gif"></td>
						<td align="left"><a href="hiscores9d0f.html?table=14">
						Smithing
						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_mining1.gif"></td>
						<td align="left"><a href="hiscores84d6.html?table=15">
						Mining
						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_herblore1.gif"></td>
						<td align="left"><a href="hiscores2e3e.html?table=16">

						Herblore
						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_agility1.gif"></td>
						<td align="left"><a href="hiscorese09e.html?table=17">
						Agility
						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_thieving1.gif"></td>
						<td align="left"><a href="hiscores7202.html?table=18">
						Thieving
						</a></td>
						</tr>

						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_slayer1.gif"></td>
						<td align="left"><a href="hiscores6d9b.html?table=19">
						Slayer
						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_farming1.gif"></td>
						<td align="left"><a href="hiscores87f5.html?table=20">
						Farming
						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_runecraft1.gif"></td>

						<td align="left"><a href="hiscores2b90.html?table=21">
						Runecraft
						</a></td>
						</tr>
						<tr>
						<td> </td>
						<td><img class="miniimg" src="../img/hiscores/skill_icon_hunter1.gif"></td>
						<td align="left"><a href="hiscoresf323.html?table=22">
						Hunter
						</a></td>
						</tr>
						<tr>
							<td> </td>
							<td><img class="miniimg" src="../img/hiscores/skill_icon_construction1.gif"></td>
							<td align="left"><a href="hiscores86b5.html?table=23">Construction</a></td>
						</tr>
						<tr>
						</tr>
						<tr>
						</tr>
					</table>
				</td>
				<td width="385" valign="top" align="left">
					<img class="mainscroll-top" src="../img/scroll/scroll369_top.png" alt="" width="379" height="36" />
					<div class="mainscroll-bg">
						<div class="mainscroll-bgimg">
							<div class="mainscroll-content">
								<table cellpadding="0" cellspacing="0" valign="bottom" style="line-height:5mm" border=0>
									<tr>
										<td width="380" colspan="5" align="center">
											<b><img class="miniimg"  src="../img/hiscores/blank.gif" />  <?php echo ucFirst(getTable($_GET['table'])) ?> Hiscores</b>
										</td>
									</tr>
									<tr>
										<td width="60"></td>
										<td width="120"></td>
										<td width="70"></td>
										<td width="100"></td>
										<td width="30"></td>
									</tr>
<?php
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM highscores_skills"),0) or die(mysql_error());
$offset = (isset($_GET["rank"]) && is_numeric($_GET["rank"]) && $_GET["rank"] < $count) ? $_GET["rank"] : 0;
$row = mysql_query("SELECT * FROM highscores_skills ORDER BY ".getTable($_GET['table'])."LVL desc, ".getTable($_GET['table'])."XP desc LIMIT $offset, ".($offset + 21)."") or die (mysql_error());
while($query = mysql_fetch_assoc($row)) {
	$usernames[] = $query['username'];
	$levels[] = $query[''.getTable($_GET['table']).'LVL'];
	$exps[] = $query[''.getTable($_GET['table']).'XP'];
}
?>
									<tr style="line-height:5mm" >
											<td align="right">
												<b>Rank </b><br />
												<!--<span style="color: #AD003E;">1</span>  -->
												<?php
													$d = $_GET['rank'] + 21;
													$u = $_GET['rank'] - 21;
													if($_GET['rank'] == 0 || $_GET['rank'] == null){
														$rank = 1;
													} else {
														$rank = $_GET['rank'];
													}
													if($_GET['rank'] > 1){
														for($i = $rank; $i < ($_GET['rank'] + 21); $i++) {
															if($i > $count){
															} else {
																echo '<span>'.$i.'</span>  <br/>';
															}
														}
													} else {
														for($i = $rank; $i < ($_GET['rank'] + 22); $i++) {
															if($i > $count){
															} else {
																echo '<span>'.$i.'</span>  <br/>';
															}
														}
													}
												?>
											</td>
											<td align="left">
												<b>Name</b><br />
												<!--<a style="color: #AD003E;" href="hiscorepersonal0965.html?user1=edgeville">Edgeville</a><br />-->
												<?php
													if($rank == 1){
														$rank = 0;
													}
													for($i = $rank; $i < ($rank + 21); $i++) {
														if($i > $count){
														} else {
															echo '<a href="personal.ws?user1='.$usernames[$i].'">'.ucWords($usernames[$i]).'</a><br/>';
														}
													}
												?>
											</td>
											<td align="right">
												<b>Level</b><br />
												<!--<span style="color: #AD003E;">406</span><br />-->
												<?php
													for($i = $rank; $i < $d; $i++) {
														if($i > $count){
														} else {
															echo $levels[$i].'<br/>';
														}
													}
												?>
											</td>
											<td align="right">
												<b>XP</b><br />
												<!--<span style="color: #AD003E;">1,370,349</span><br />-->
												<?php
													for($i = $rank; $i < $d; $i++) {
														if($i > $count){
														} else {
															echo ''.dots($exps[$i]).'<br/>';
														}
													}
												?>
											</td>
										<td valign="middle">
											<table>
												<tr>
													<td width="30" valign="top">
															<a href="index.ws?table=<?php echo $_GET['table']; ?>&rank=<?php echo $u; ?>" title="Scroll up table">
																<font color="#DDDDDD">
																	<img src="../img/hiscores/arrow_up.png" alt="Scroll Up" />
																</font>
															</a>
													</td>
												</tr>
												<tr>
													<td width="30" valign="bottom">
															<a href="index.ws?table=<?php echo $_GET['table']; ?>&rank=<?php echo $d; ?>" title="Scroll down table">
																<font color="#DDDDDD">
																	<img src="../img/hiscores/arrow_down.png" alt="Scroll Down" />
																</font>
															</a>
													</td>
												</tr>
											</table>
										</td> 
									</tr>
								</table>
							</div>
						</div>
					</div>
					<img class="mainscroll-bottom" src="../img/scroll/scroll369_bottom.png" alt="" width="379" height="36" />
				</td>
				<td width="150" valign="top">
					<table cellpadding="0" cellspacing="0" style="line-height:5mm" border=0>
						<tr>
							<td>
								<div height="25px" width="1"></div><br />
							</td>
						</tr>
						<tr>
							<td>
								<form action="hiscorepersonal.ws" method="post" style="margin:0px; padding:0px;">
									<div class="hiscorebutton">
										<span>
										<b>Search by name</b><br />
										<input size="14" style="margin: 2px; margin-top: 5px;" maxlength="12" type="text" name="user1" value="" /><br />
										<input size="14" maxlength="12" type="submit" name="submit" value="Search" />
										</span>
									</div>
								</form>
							</td>
						</tr>
						<tr>
							<td>
								<div height="15px" width="1"></div><br />
							</td>
						</tr>
						<tr>
							<td>
								<form action="#" method="POST" style="margin:0px; padding:0px;">
									<div class="hiscorebutton">
										<span>
											<b>Search by rank</b><br />
											<input size="14" style="margin:2px" maxlength="12" type="text" name="rank" value="" /><br />
											<input type="hidden" name="table" value="0" />
											<input type="submit" name="submit" value="Search" />
										</span>
									</div>
								</form>
							</td>
						</tr>
													<!--<tr>
							<td>
								<div height="15px" width="1"></div><br />
							</td>
						</tr>
						<tr>
							<td>
								<form action="login.ws" method="POST" style="margin:0px;padding:0px;">
									<div class="hiscoremediumbutton">
										<span>
											<br /><b>Friends Hiscores</b><br /><br />
											To view personal<br />
											hiscores and compare<br />
											yourself to your friends<br />
											<img height="9px" width="1" src="http://img/hiscores/spacer.gif" /><br />
											<input size="14"  maxlength="12" type="submit" name="action" value="Log In" />
										</span>
									</div>
								</form>
							</td>
						</tr>-->
					</table>
				</td>
			</tr>
		</table>

<div class="tandc"><?php getFooter(); ?><br>Most of the pictures on this website are copyright © 1999 - 2011 <a href="http://jagex.com">Jagex Ltd</a>.</div>
		</div>
</body>
</html>

It's quite messy.

Link to comment
Share on other sites

I don't know why I missed this.

 

Your LIMIT X, X+21

 

Should be LIMIT X, 21

 

You are running out of results and your are referencing your loop wrong.

 

for($i = $rank; $i < ($rank + 21); $i++) {

if($i > $count){

} else {

echo '<a href="personal.ws?user1='.$usernames[$i].'">'.ucWords($usernames[$i]).'</a><br/>';

}

}

 

Should be

 

for($i = 0; $i < 21); $i++) {
	echo '<a href="personal.ws?user1='.$usernames[$i].'">'.ucWords($usernames[$i]).'</a><br/>';
}

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.