Jump to content

Archived

This topic is now archived and is closed to further replies.

wookie

Small problem

Recommended Posts

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

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

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?
[code]
        // 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';

?>
[/code]

Many thanks!!

Wookie

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Okay, here is the whole code...

[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';

?>

[/code]

Many thanks..

Wookie

Share this post


Link to post
Share on other sites

×

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.