Jump to content


Photo

Small problem


  • Please log in to reply
2 replies to this topic

#1 wookie

wookie
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 02 May 2006 - 01:02 PM

Hi all,

I'm pretty new to coding and have got by for several months, copy and pasting with a huge dose of trial and error. The two combined have helped me be quite successful. The following error however has me helplessly confused, because I'm sure there is a simple remedy.

Its the TWO parts "SELECT from sabs", the first one is enclosed in these /* */.

I can get one or the other to work but not both at the same time or I get an error "unexpected ELSE" which applies to this part of the code

       }else{
                $site['content'] .= '<br /><br /><h3>Please select a category!</h3>';
        }

But if I use just the one as in the following, no errors. How do I get both to work? And if you have the time and the inclination could you explain why to me?
        // display the target details
        }elseif($args['name']){
                if($args['sab']){
                   $site['content'] .= include "sabs.php";
                }
                $str = "SELECT * FROM `targets` WHERE `targetName` = '$args[name]'";
                $q = mysql_query($str)or die(mysql_error());
                if(!$q){
                        Echo "couldnt receive target";
                }else{
                        $site['content'] .= '<br /><br /><h3>'.$args['name'].'</h3>';
                        while($row=mysql_fetch_array($q)){
                                $name = getUserName($row['userID']);
                                $site['content'] .= 'Added by '.$name.' on '.date("F d. Y", $row['time']).'<br /><br />Link: <a href="http://www.kingsofchaos.com/stats.php?id='.$row['targetStats'].'" target="_blank">'.$args['name'].'</a><br /><br />Reason: '.$row['reason'];
                        }

         /*               // get the amount of damage this target received
                        $str = "SELECT * FROM `sabs` WHERE `sabName` = '$args[name]'";
                        $q = mysql_query($str)or die(mysql_error());
                        if(!$q){
                            Echo "couldnt receive target damage";
                        }else{
                                $thisDamage = 0;
                                while($row=mysql_fetch_array($q)){
                                      $wep_value = getWepValue($row['weapon']);
                                      $this_value = $row['amount'] * $wep_value;
                                      $thisDamage += $this_value;
                                }*/
                       // get the amount of Gold this target's waepons cost
                        $str = "SELECT * FROM `sabs` WHERE `sabName` = '$args[name]'";
                        $q = mysql_query($str)or die(mysql_error());
                        if(!$q){
                            Echo "couldnt receive target damage";
                        }else{
                                $thisDamagee = 0;
                                while($row=mysql_fetch_array($q)){
                                      $wepp_value = DepCost($row['weapon']);
                                      $this_value = $row['amount'] * $wepp_value;
                                      $thisDamagee += $this_value;
                                }                                
                                $site['content'] .= '<br /><br />Damage taken by our spies: '.number_format($thisDamage);
                                $site['content'] .= '<br /><br />Gold value taken of Sabotaged weapons: '.number_format($thisDamagee);                                
                        }
                        $site['content'] .= '<br /><br /><form action="'.$PHP_SELF.'?name='.$args['name'].'" method="post">Submit a sab on this user:<br /><textarea name="sab" cols="50" rows="5">Copy the Sab log into here (like "Your chief of intelligence...")</textarea><br /><input type="submit" value="Submit My Sab"></form>';
                }
       }else{
                $site['content'] .= '<br /><br /><h3>Please select a category!</h3>';
        }

}else{
        $site['message'] = 'You may login now or register a new account';
        $site['content'] = "You have to login to view that page!";
}
$site['message'] = ($args['str'] ? $args['str'] : $site['message']);
include 'template.php';

?>

Many thanks!!

Wookie

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 02 May 2006 - 02:38 PM

can you post the whole code. Your code starts with an elseif. looks like you may have a problem missing a curly bracket. but can't tell with the code you have given.

One thing you way want to try, is rename your queries. Anytime you run more than one query on a page you should have different names for them.
Use $str and $str2, $q and $q2, $row and $row2.

Ray

#3 wookie

wookie
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 02 May 2006 - 03:48 PM

Okay, here is the whole code...

<?

include 'functs.php';

$site['name'] = __FILE__;
$site['heading'] = 'Wars and Targets!';

// if the user is logged in
if($_SESSION["id"] && $_SESSION["name"]){

        // get all Target categories
        $str = "SELECT * FROM `wars`";
        $q = mysql_query($str)or die(mysql_error());
        if(!$q){
                Echo "couldnt receive categories";
        }else{
                $i = 0;
                $site['content'] .= '<ul id="subnav">';
                while($row=mysql_fetch_array($q)){
                        $site['content'] .= '<li>'.(($i != 0) ? '|&nbsp;&nbsp;' : '').'<a href="?type='.$row['short'].'">'.$row['warName'].'</a></li>';
                        $i++;
                }
                $site['content'] .= '</ul>';
        }

        // display a specific category
        if($args['type']){
                $str = "SELECT t1.*, t2.* FROM `targets` AS t1, `wars` AS t2 WHERE t2.`short` = '$args[type]' AND t1.`warID` = t2.`ID`";
                $q = mysql_query($str)or die(mysql_error());
                if(!$q){
                        Echo "couldnt receive targets";
                }else{
                        $i = 0;
                        while($row=mysql_fetch_array($q)){
                                if($i == 0)
$site['content'] .= '<br /><br /><h3>'.$row['warName'].'</h3><br /><br />Reason: '.$row['reason'].'<ul>';
                                $site['content'] .= '<li><a href="?name='.$row['targetName'].'">'.$row['targetName'].'</a></li>';
                                $i++;
                        }
                        $site['content'] .= '</ul>';
                }

        // display the target details
        }elseif($args['name']){
                if($args['sab']){
                   $site['content'] .= include "sabs.php";
                }
                $str = "SELECT * FROM `targets` WHERE `targetName` = '$args[name]'";
                $q = mysql_query($str)or die(mysql_error());
                if(!$q){
                        Echo "couldnt receive target";
                }else{
                        $site['content'] .= '<br /><br /><h3>'.$args['name'].'</h3>';
                        while($row=mysql_fetch_array($q)){
                                $name = getUserName($row['userID']);
                                $site['content'] .= 'Added by '.$name.' on '.date("F d. Y", $row['time']).'<br /><br />Link: <a href="http://www.kingsofchaos.com/stats.php?id='.$row['targetStats'].'" target="_blank">'.$args['name'].'</a><br /><br />Reason: '.$row['reason'];
                        }

         /*               // get the amount of damage this target received
                        $str = "SELECT * FROM `sabs` WHERE `sabName` = '$args[name]'";
                        $q = mysql_query($str)or die(mysql_error());
                        if(!$q){
                            Echo "couldnt receive target damage";
                        }else{
                                $thisDamage = 0;
                                while($row=mysql_fetch_array($q)){
                                      $wep_value = getWepValue($row['weapon']);
                                      $this_value = $row['amount'] * $wep_value;
                                      $thisDamage += $this_value;
                                }*/
                       // get the amount of Gold this target's waepons cost
                        $str = "SELECT * FROM `sabs` WHERE `sabName` = '$args[name]'";
                        $q = mysql_query($str)or die(mysql_error());
                        if(!$q){
                            Echo "couldnt receive target damage";
                        }else{
                                $thisDamagee = 0;
                                while($row=mysql_fetch_array($q)){
                                      $wepp_value = DepCost($row['weapon']);
                                      $this_value = $row['amount'] * $wepp_value;
                                      $thisDamagee += $this_value;
                                }                                
                                $site['content'] .= '<br /><br />Damage taken by our spies: '.number_format($thisDamage);
                                $site['content'] .= '<br /><br />Gold value taken of Sabotaged weapons: '.number_format($thisDamagee);                                
                        }
                        $site['content'] .= '<br /><br /><form action="'.$PHP_SELF.'?name='.$args['name'].'" method="post">Submit a sab on this user:<br /><textarea name="sab" cols="50" rows="5">Copy the Sab log into here (like "Your chief of intelligence...")</textarea><br /><input type="submit" value="Submit My Sab"></form>';
                }
       }else{
                $site['content'] .= '<br /><br /><h3>Please select a category!</h3>';
        }

}else{
        $site['message'] = 'You may login now or register a new account';
        $site['content'] = "You have to login to view that page!";
}
$site['message'] = ($args['str'] ? $args['str'] : $site['message']);
include 'template.php';

?>


Many thanks..

Wookie




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users