Jump to content

problem with a FOR within a FOR


mforan

Recommended Posts

Im having a problem with a for within a for.

when the inner for has got results the outer for only displays 1 result. the outer for stops looping.

when the inner for doesnt have any results, there is just a blank screen.

 

any advise?

<?php
include("../db/dbinfo.inc.php");
if (!$loadeddbinfo) { die("<br><br><center>dbinfo couldnt be loaded</center></body></html>"); }
include("loginverify.inc.php");
if (!$loadedloginverify) { mysql_close(); die("<br><br><center>loginverify couldnt be loaded</center></body></html>"); }
include("agreement.inc.php");
if (!$loadedagreement) { mysql_close(); die("<br><br><center>agreement couldnt be loaded</center></body></html>"); }
include("ipcheck.inc.php");
if (!$loadedipcheck) { mysql_close(); die("<br><br><center>IP ADDRESS Tracking system couldnt be loaded</center></body></html>"); }
include("killed.inc.php");
if (!$loadedkillcheck) { mysql_close(); die("<br><br><center>killed checker couldnt be loaded</center></body></html>"); }
include("incomeupdate.inc.php");
if (!$loadedincomeupdate) { mysql_close(); die("<br><br><center>incomeupdate couldnt be loaded</center></body></html>"); }

if ($_POST['support_submit']) {
$buildchange[1] = $info[3];
$buildchange[2] = time();
$buildchange[3] = $_POST['subject'] = ereg_replace("[^A-Za-z0-9\ \]", "", $_POST['subject']);
$buildchange[3] = substr($buildchange[3], 0, 100);
$buildchange[4] = "Open";
$buildchange[5] = $_POST['category'] = ereg_replace("[^A-Za-z0-9]", "", $_POST['category']);
$buildchange[5] = substr($buildchange[5], 0, 50);
$buildchange[7] = ereg_replace("\'", "&#0039;", $_POST['message']);
$buildchange[7] = ereg_replace("\<", "&#0060;", $buildchange[7]);
$buildchange[7] = ereg_replace("\>", "&#0062;", $buildchange[7]);
$buildchange[7] = ereg_replace("\n", "<br>", $buildchange[7]);
$buildchange[7] = substr($buildchange[7], 0, 6048);

$query = "SELECT identity FROM sumessages WHERE sender='$info[3]' ORDER BY identity DESC LIMIT 1";
$result = mysql_query($query) or die("Error: ".mysql_error());
$identity = array();
$identity = mysql_fetch_array($result, MYSQL_NUM);

$buildchange[9] = $identity[0] + 1;

if ($buildchange[3]) {
	if ($buildchange[7]) {
	$query = "INSERT INTO sumessages SET sender='$buildchange[1]',date='$buildchange[2]',subject='$buildchange[3]',status='$buildchange[4]',category='$buildchange[5]',message='$buildchange[7]',identity='$buildchange[9]'";
	mysql_query($query) or die("Error: ".mysql_error());
	$a = "Your support enquiry has been successfully sent!";
	} else {
	$a = "ERROR: Enquiry must contain a message.";
	}
} else {
$a = "ERROR: Enquiry must contain a subject.";
}
}

if ($_POST['message']) {
if ($_POST['delete']) {
$delete[0] = $_POST['identity'] = ereg_replace("[^0-9]", "", $_POST['identity']);
$query = "DELETE FROM sumessages WHERE identity='$delete[0]'";
mysql_query($query) or die("Error: ".mysql_error()." ".$query);
$a = "Support enquiry successfully deleted.";
}
}
?>
<html>
<head>
<title>RECRUITMENT</title>
<link href="color.css.php" rel="StyleSheet" type="text/css">
<link href="style.css" rel="StyleSheet" type="text/css">
</head>
<body>
<center>
<?php 
include("banner.php");
if (!$loadedbanner) { mysql_close(); die("<br><br><center>banner couldnt be loaded</center></body></html>"); }
include("bancheck.inc.php");
if (!$loadedbancheck) { mysql_close(); die("<br><br><center>ban check system couldnt be loaded</center></body></html>"); }
include("newsupdate.inc.php");
if (!$loadednewsupdate) { mysql_close(); die("<br><br><center>newsupdate couldnt be loaded</center></body></html>"); }
include("militaryupdate.inc.php");
if (!$loadedmilitaryupdate) { mysql_close(); die("<br><br><center>militaryupdate couldnt be loaded</center></body></html>"); }
include("updateusers.inc.php");
if (!$loadedupdateusers) { mysql_close(); die("<br><br><center>updateusers couldnt be loaded</center></body></html>"); }
include("downtime.inc.php");
if (!$loadeddt) { mysql_close(); die("<br><br><center>downtime protocol couldnt be loaded</center></body></html>"); }
include("statsbar.inc.php");
if (!$loadedstatsbar) { mysql_close(); die("<br><br><center>statsbar couldnt be loaded</center></body></html>"); }

if ($_POST) {echo "$a<br><br><br>";}
?>
<table width="90%" border="0" cellpadding="0" cellspacing="0">
<tr>
  <td colspan="2"><table width="100%" class="metal" cellpadding="3" cellspacing="3">
      <tr>
        <td class="head"><center>
            <font size="6"><b>Support</b></font>
        </center></td>
      </tr>
    </table></td>
</tr>
<td width="67%" colspan="1" align="center" valign="top"><br>
  <br>
      Welcome <a class="noline"><?php echo$info[8]," ",$info[0]; ?></a>.<br>
        If you need help with a certain aspect of the game, you can ask for it here.<br>
        <br>
        <form action="support.php" method="post">
        <table width="53%" align="center" cellpadding="3" cellspacing="3" class="metal">
          <tr>
            <td class="head" colspan="2">Ask Ambroid Support a question
            </th>          </tr>
          <tr valign="top">
            <td width="21%" class="variable">Category:</td class="variable">
            <td width="79%" class="variable"><select name="category" id="category">
                <option value="General">General</option>
                <option value="Cheat">Cheat Report</option>
                <option value="Glitch">Game Glitch</option>
                <option value="Abuse">Abuse from other user</option>
                <option value="Multiply attacked">Multiply attacked by user</option>
                <option value="Multiple Accounts">Suspected multiple account</option>
                <option value="Premium">Premium enquiry</option>
                <option value="Deleting Account">Deleting Account problem</option>
                <option value="Banned">Why have i been banned?</option>
                <option value="Barred">Barred from game</option>
              </select>
                </label></td>
          </tr>
          <tr valign="top">
            <td width="21%" class="variable">Subject:</td class="variable">
            <td class="variable"><a class="noline">
              <input name="subject" type="text" id="subject" size="50" class="text" maxlength="100">
            </a></td>
          </tr>
          <tr valign="top">
            <td class="variable"><b>Message:</b></td class="variable">
            <td class="variable"><textarea name="message" rows=7 cols=50 maxlength="20" id="message"></textarea></td>
          </tr>
          <tr valign="top">
            <td class="variable">Attachment:</td class="variable">
            <td class="variable"> </td>
          </tr>
        </table>
        <input name="support_submit" type="submit" class="submit" value="Send">
        </form>
        <br>
      <table width="100%" border="0">
        <tr>
          <td>
<?php
$query = "SELECT * FROM sumessages WHERE sender='$info[3]' AND reply ='0' ORDER BY date ASC";
$result = mysql_query($query) or die("Error: ".mysql_error());
$support = array();
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {$support[] = $row;}

for ($i = 0; $i < count($support); $i++) {
?>

            <br>
            <form action="support.php" method="post" name="message">
              <table width="80%" align="center" cellpadding="3" cellspacing="3" class="metal">
                <tr>
                  <td class="head"><?php echo $support[$i][3]; ?> - <?php echo $support[$i][5]; ?></td>
                </tr>
                <tr>
                  <td class="variable" valign="top" align="left"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                      <tr>
                        <td width="50%" valign="top">Date Opened:</td>
                        <td width="50%" valign="top"><a class="variable"><?php echo date('d.m.Y H:i', $support[$i][2]); ?></a></td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td width="50%"> </td>
                      </tr>
                      <tr>
                        <td width="50%" valign="top">Category:</td>
                        <td width="50%" valign="top"><a class="variable"><?php echo $support[$i][5]; ?></a></td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td width="50%"> </td>
                      </tr>
                      <tr>
                        <td width="50%" valign="top">Subject:</td>
                        <td width="50%" valign="top"><a class="variable"><?php echo $support[$i][3]; ?></a></td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td width="50%"> </td>
                      </tr>
                      <tr>
                        <td width="50%" valign="top">Message:</td>
                        <td width="50%" valign="top"><a class="variable"><?php echo $support[$i][7]; ?></a></td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td width="50%"> </td>
                      </tr>
                      <tr>
                        <td width="50%" valign="top">Status:</td>
                        <td width="50%" valign="top"><a class="variable"><?php echo $support[$i][4]; ?></a></td>
                      </tr>                     
                       <?php 
					$query = "SELECT COUNT(date) FROM sumessages WHERE sender='$info[3]' AND identity='".$support[$i][10]."'";
					$result = mysql_query($query) or die("Error: ".mysql_error());
					$countd = mysql_fetch_array($result, MYSQL_NUM);

				   if ($countd[0] > 1) { 
				   
					$query = "SELECT date FROM sumessages WHERE sender='$info[3]' AND identity='".$support[$i][10]."' ORDER BY date DESC LIMIT 1";
					$result = mysql_query($query) or die("Error: ".mysql_error());
					$daten = array();
					$daten = mysql_fetch_array($result, MYSQL_NUM);
				   ?>
                      <tr>
                        <td> </td>
                        <td width="50%"> </td>
                      </tr>
                      <tr>
                        <td width="50%" valign="top">Last Update:</td>
                        <td width="50%" valign="top"><a class="variable"><?php echo date('d.m.Y H:i', $daten[0]); ?></a></td>
                      </tr>
                      <?php } ?>
                    </table></td>
                </tr>
                <tr>
                  <td class="variable" valign="top" align="left"><?php if ($support[$i][4] !="Closed") {?><div align="center">On-going enquiry:</div><br>
                    <?php 
$query = "SELECT * FROM sumessages WHERE reply='1' AND identity='".$support[$i][10]."' ORDER BY date ASC";
$result = mysql_query($query) or die("Error: ".mysql_error());
$supportf = array();
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {$supportf[] = $row;}
echo count($supportf);
for ($i = 0; $i < count($supportf); $i++) {

if ($supportf[$i][8]){
$a = "MOD ".$supportf[$i][8]." - ";
} else { $a = "".$supportf[$i][1]." - "; }
$a .= date('d.m.Y H:i', $supportf[$i][6]);
$a .= "<br>";
$a .= "<a class='variable'>".$supportf[$i][7]."</a><br><br>";
echo $a;
}
				?>
                      <div align="center"><input name="reply" type="submit" class="submit" value="Add Message" id="reply"></div>
                      <br>
                      <?php } ?><div align="center">
                      <input name="identity" type="hidden" value="<?php echo $support[$i][10]; ?>">
                      <input name="message" type="hidden" value="1">
                      <input name="delete" type="submit" class="submit" value="Delete Enquiry" id="delete">
                  </div></td>
                </tr>
              </table>
            </form><br><?php }?>
          </td>
        </tr>
      </table></td>
    </tr>
  </table><br>
      <?php
include("banner.php");
if (!$loadedbanner) { mysql_close(); die("<br><br><center>banner couldnt be loaded</center></body></html>"); }
?>
</center>
</body>
</html>
<?php
mysql_close();
?>

Link to comment
Share on other sites

You only have two for loops in that entire code, one inside the other, and both use the variable $i.

 

Essentially this is what you've done:

 

<?php
for( $i = 0; $i < 5; $i += 1 ) {
    echo "before inner, i is {$i}" . PHP_EOL;
    for( $i = 0; $i < 10; $i += 1 ) {
        echo "inner loop, i is {$i}" . PHP_EOL;
    }
    echo "after inner, i is {$i}" . PHP_EOL;
}
?>

 

Run that program and see if it doesn't make more sense as to why the outer loop isn't looping.

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.