mrt003003 Posted May 3, 2011 Share Posted May 3, 2011 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 https://forums.phpfreaks.com/topic/235441-if-statement-not-working/ Share on other sites More sharing options...
fugix Posted May 3, 2011 Share Posted May 3, 2011 an Undefined index: error indicates that either that index doesnt exist or hasnt been set Link to comment https://forums.phpfreaks.com/topic/235441-if-statement-not-working/#findComment-1209977 Share on other sites More sharing options...
mrt003003 Posted May 3, 2011 Author Share Posted May 3, 2011 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 https://forums.phpfreaks.com/topic/235441-if-statement-not-working/#findComment-1209979 Share on other sites More sharing options...
minidak03 Posted May 3, 2011 Share Posted May 3, 2011 Double check your array using print_r() to make sure everything is set correctly. Link to comment https://forums.phpfreaks.com/topic/235441-if-statement-not-working/#findComment-1209982 Share on other sites More sharing options...
mrt003003 Posted May 3, 2011 Author Share Posted May 3, 2011 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 https://forums.phpfreaks.com/topic/235441-if-statement-not-working/#findComment-1209985 Share on other sites More sharing options...
fugix Posted May 3, 2011 Share Posted May 3, 2011 your if statements with $_SESSION['MM_Username'] arent working or your if statements with the classes? Link to comment https://forums.phpfreaks.com/topic/235441-if-statement-not-working/#findComment-1209987 Share on other sites More sharing options...
mrt003003 Posted May 3, 2011 Author Share Posted May 3, 2011 The $_SESSION['MM_Username'] is working as i can confirm the data thats echoed. So the problems with the If statment with the classes. Link to comment https://forums.phpfreaks.com/topic/235441-if-statement-not-working/#findComment-1209988 Share on other sites More sharing options...
mrt003003 Posted May 3, 2011 Author Share Posted May 3, 2011 I forgot to add the _totlas or _totla to the Class.. oops Link to comment https://forums.phpfreaks.com/topic/235441-if-statement-not-working/#findComment-1209999 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.