Jump to content

If statement not working


mrt003003

Recommended Posts

Hi there im having trouble with my If statement in that its not doing what it is suppose to do!

 

I have a do loop that and If statament that checks that resultp < results. If it is less then an echo is suppose to happen, but its not. Im getting notice errors: Undefined index: Class1- 4 but nothing is outputted. I checked the records in the database so the condition will happen but nothings happening.

 

Help

 

 <?php do { ?>
    
    <?php 

echo $row_resultp['Class1_totla']; echo ' Class 1';
echo'<br>';
echo $row_resultp['Class2_totla']; echo ' Class 2'; echo'<br>';
echo $row_resultp['Class3_totla']; echo ' Class 3'; echo'<br>';
echo $row_resultp['Class4_totla']; echo ' Class 4';

echo'<br>';echo'<br>';echo'<br>';

echo $row_results['Class1_totlas']; echo ' Class 1';
echo'<br>';
echo $row_results['Class2_totlas']; echo ' Class 2'; echo'<br>';
echo $row_results['Class3_totlas']; echo ' Class 3'; echo'<br>';
echo $row_results['Class4_totlas']; echo ' Class 4';

if ($row_resultp['Class1'] < $row_results['Class1']){
echo 'you need';
echo $row_resultp['Class1'] - $row_results['Class1'];
echo 'more'; }

if ($row_resultp['Class2'] < $row_results['Class2']){
echo 'you need';
echo $row_resultp['Class2'] - $row_results['Class2'];
echo 'more';}

if ($row_resultp['Class3'] < $row_results['Class3']){
echo 'you need';
echo $row_resultp['Class3'] - $row_results['Class3'];
echo 'more'; }

if ($row_resultp['Class4'] < $row_results['Class4']){
echo 'you need';
echo $row_resultp['Class4'] - $row_results['Class4'];
echo 'more'; }

?>
    <?php } while ($row_resultp = mysql_fetch_assoc($resultp) && ($row_results = mysql_fetch_assoc($results))); ?>

Link to comment
Share on other sites

Hmm ok, i thought it was set, heres the code in full:

<?php $colname_results = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_results = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_swb, $swb);
$query_results = sprintf("SELECT SUM(Class1) As Class1_totlas, SUM(Class2) As Class2_totlas, SUM(Class3) As Class3_totlas, SUM(Class4) As Class4_totlas FROM ships WHERE PlayerName = %s", GetSQLValueString($colname_results, "text"));
$results = mysql_query($query_results, $swb) or die(mysql_error());
$row_results = mysql_fetch_assoc($results);
$totalRows_results = mysql_num_rows($results);

$colname_resultp = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_resultp = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_swb, $swb);
$query_resultp = sprintf("SELECT SUM(Class1) As Class1_totla, SUM(Class2) As Class2_totla, SUM(Class3) As Class3_totla, SUM(Class4) As Class4_totla FROM planet WHERE PlayerName = %s", GetSQLValueString($colname_resultp, "text"));
$resultp = mysql_query($query_resultp, $swb) or die(mysql_error());
$row_resultp = mysql_fetch_assoc($resultp);
$totalRows_resultp = mysql_num_rows($resultp);

<?php do { ?>
    
    <?php 

echo $row_resultp['Class1_totla']; echo ' Class 1';
echo'<br>';
echo $row_resultp['Class2_totla']; echo ' Class 2'; echo'<br>';
echo $row_resultp['Class3_totla']; echo ' Class 3'; echo'<br>';
echo $row_resultp['Class4_totla']; echo ' Class 4';

echo'<br>';echo'<br>';echo'<br>';

echo $row_results['Class1_totlas']; echo ' Class 1';
echo'<br>';
echo $row_results['Class2_totlas']; echo ' Class 2'; echo'<br>';
echo $row_results['Class3_totlas']; echo ' Class 3'; echo'<br>';
echo $row_results['Class4_totlas']; echo ' Class 4';

if ($row_resultp['Class1'] < $row_results['Class1']){
echo 'you need';
echo $row_resultp['Class1'] - $row_results['Class1'];
echo 'more'; }

if ($row_resultp['Class2'] < $row_results['Class2']){
echo 'you need';
echo $row_resultp['Class2'] - $row_results['Class2'];
echo 'more';}

if ($row_resultp['Class3'] < $row_results['Class3']){
echo 'you need';
echo $row_resultp['Class3'] - $row_results['Class3'];
echo 'more'; }

if ($row_resultp['Class4'] < $row_results['Class4']){
echo 'you need';
echo $row_resultp['Class4'] - $row_results['Class4'];
echo 'more'; }

?>
    <?php } while ($row_resultp = mysql_fetch_assoc($resultp) && ($row_results = mysql_fetch_assoc($results))); 
mysql_free_result($results);
mysql_free_result($resultp);

 

Wheres the problem with it?

 

 

Thanks

Link to comment
Share on other sites

i have done and these are outputted:

echo $row_resultp['Class1_totla']; echo ' Class 1';
echo'<br>';
echo $row_resultp['Class2_totla']; echo ' Class 2'; echo'<br>';
echo $row_resultp['Class3_totla']; echo ' Class 3'; echo'<br>';
echo $row_resultp['Class4_totla']; echo ' Class 4';

echo'<br>';echo'<br>';echo'<br>';

echo $row_results['Class1_totlas']; echo ' Class 1';
echo'<br>';
echo $row_results['Class2_totlas']; echo ' Class 2'; echo'<br>';
echo $row_results['Class3_totlas']; echo ' Class 3'; echo'<br>';
echo $row_results['Class4_totlas']; echo ' Class 4';

 

Its just the if statement that doesnt work. :)

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.