Changes to loop do nothing
Moderator: General Moderators
Changes to loop do nothing
I had a loop like..
i=0, i<5, i++
and it works fine
but when i change it to
i=2, i<7, i++
the results on the page stay the same
any ideas?
i=0, i<5, i++
and it works fine
but when i change it to
i=2, i<7, i++
the results on the page stay the same
any ideas?
I get the same results no matter what I set $begin and $end to.
Code: Select all
if($cat == 'random'){
$sql1="SELECT * FROM `arcade_games` ORDER BY `title`";
}
else{
$sql="SELECT * FROM `arcade_categories` WHERE `catname` = '$cat' LIMIT 1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
$maincat = $row["catid"];
$sql1="SELECT * FROM `arcade_games` WHERE `categoryid` = '$maincat' ORDER BY `shortname`";
}
$result1=mysql_query($sql1);
$gamenum = mysql_num_rows($result1);
if ($gamenum < 20){
$begin = 0;
$end = $gamenum;
}
else if ( isset($_GET['begin']) ) {
$begin = $_GET['begin'];
$end = $begin + 20;
}
else {
$begin = 0;
$end = 20;
}
for($i = $begin; $i < $end; $i++) {
$row = mysql_fetch_array($result1);
$shortname = $row["shortname"];
$title = $row["title"];
$gameid = $row["gameid"];
$stdimage = $row["stdimage"];
$description = $row["description"];
$thiscat = $row["categoryid"];
$isreverse = $row["isreverse"];
$sql2="SELECT * FROM `arcade_categories` WHERE `catid` = '$thiscat' LIMIT 1";
$result2=mysql_query($sql2);
$row = mysql_fetch_array($result2);
$tempcat = $row["catname"];
if($isreverse == 1){
$sql3="SELECT * FROM `arcade_highscores` WHERE `gamename` = '$gameid' ORDER BY `score` LIMIT 1";
}
else{
$sql3="SELECT * FROM `arcade_highscores` WHERE `gamename` = '$gameid' ORDER BY `score` DESC LIMIT 1";
}
$result3=mysql_query($sql3);
$champnum = mysql_num_rows($result3);
if($champnum == 1){
$row = mysql_fetch_array($result3);
$champname = $row["username"];
$champscore = $row["score"];
}
else {
$champname = "None";
$champscore = 0;
}
$user = $VAR[4];
$sql4="SELECT * FROM `arcade_highscores` WHERE `gamename` = '$gameid' AND `username` = '$user' ORDER BY `score` DESC LIMIT 1";
$result4=mysql_query($sql4);
$row4 = mysql_fetch_array($result4);
$scorenum = mysql_num_rows($result4);
if($scorenum == 1){
$yourscore = $row4["score"];
}
else {
$yourscore = "None";
}
echo "
<table style='width:100%;'>
<tr>
<td style='width:15%;text-align:center;font-size:11pt;' class='color'>
<a href='$VAR[0]/arcade.php?play=$gameid'><img src='/arcade/images/$stdimage' border='2'></a>
</td>
<td style='width:30%;vertical-align:top;font-size:11pt;' class='color'>
<b><a href='$VAR[0]/arcade.php?play=$gameid'>$title</a></b>
<div style='font-size:10pt;'>
$description
</div>
</td>
<td style='width:15%;text-align:center;font-size:11pt;' class='color'>
<b>$tempcat</b><br />
(<a href='$VAR[0]/arcade.php?cat=$tempcat'>More</a>)</td>
<td style='width:20%;text-align:center;font-size:11pt;' class='color'>
<b><a href='$VAR[0]/$champname'>$champname</a></b>
<div style='font-size:10pt;'>
With a high score of:<br />
<b>$champscore</b> </div>
</td>
<td style='width:20%;text-align:center;font-size:11pt;' class='color'>
Your high score:
<br />
<b>$yourscore</b>
<br />
[<a href='$VAR[0]/arcade.php?highscore=$gameid'>High Scores</a>]
</td>
</tr>
</table>
";
}
}Code: Select all
if ($gamenum < 20){
$begin = 0;
$end = $gamenum;
}
else if ( isset($_GET['begin']) ) {
$begin = $_GET['begin'];
$end = $begin + 20;
}
else {
$begin = 0;
$end = 20;
}
for($i = $begin; $i < $end; $i++) {if they click page 2, begin is set to 20 and should show results 20-40
instead, even when begin is set, it displays results 1-20
Here is an example:
go to the bottom of the page and click 2
begin should be set to 20 but the results dont change
Last edited by Citizen on Mon Sep 25, 2006 7:06 pm, edited 1 time in total.
This may sound silly, but are you incrementing the $_GET['begin'] field when writing the generated page?Citizen wrote:the variable $begin is set by urlCode: Select all
if ($gamenum < 20){ $begin = 0; $end = $gamenum; } else if ( isset($_GET['begin']) ) { $begin = $_GET['begin']; $end = $begin + 20; } else { $begin = 0; $end = 20; } for($i = $begin; $i < $end; $i++) {
if they click page 2, begin is set to 20 and should show results 20-40
instead, even when begin is set, it displays results 1-20
what am i doing wrong?
I couldn't see any form code is all...
right
you can see it here:
http://gamerbio.com/arcade.php
just scroll to the bottom and click the "Page 1, 2, 3 " and note that no changes are made to the selection of which games are shown
you can see it here:
http://gamerbio.com/arcade.php
just scroll to the bottom and click the "Page 1, 2, 3 " and note that no changes are made to the selection of which games are shown
one tiny thing, at the end of your main table you need to close the </table> tag (missing >)Citizen wrote:right
you can see it here:
http://gamerbio.com/arcade.php
just scroll to the bottom and click the "Page 1, 2, 3 " and note that no changes are made to the selection of which games are shown
Also.. why not try spitting some debug info out from the query result to confirm that the number of rows it's detecting is in fact higher than 20? it seems to be triggering the condition of less than 20 each time.
Nice website design btw
ok, the script now shows the results before allowing page slecection.
http://www.gamerbio.com/arcade.php
and
http://www.gamerbio.com/arcade.php?begin=21
display the same results
any ideas?
http://www.gamerbio.com/arcade.php
and
http://www.gamerbio.com/arcade.php?begin=21
display the same results
any ideas?
Did you tryCitizen wrote:any ideas?
?arkady wrote:Also.. why not try spitting some debug info out from the query result to confirm that the number of rows it's detecting is in fact higher than 20?
You can add the function
Code: Select all
function dbg_mysql_query($query) {
echo '<fieldset><legend>sql query</legend>', htmlentities($query), "<br />\n";
$r = mysql_query($query);
if (!$r) {
echo mysql_error();
}
else {
echo 'num_rows: ', mysql_num_rows($r);
}
echo "</fieldset>\n";
return $r;
}