joaca Posted March 9, 2009 Share Posted March 9, 2009 Hello fellow coders. I have a problem that has haunted me for so long. I am using php $ mysql to come up with a student selection system. I have managed to retrieve my data from the database using php. However, when I try to include data from my last column into an IF statement, it doesnt work. Here is a sample of my code. please help. <code> if($_POST['sub']) { require("../scripts/opendb.php"); $result = mysql_query("select * from schools"); $num_result = mysql_num_rows($result); for($i=0; $i<$num_result; $i++) { $row = mysql_fetch_array($result); require("../scripts/create_table.php"); $resultThree = mysql_query("select * from students where firstchoice='".$row["regno"]."' or secondchoice='".$row["regno"]."' or thirdchoice='".$row["regno"]."' or fourthchoice='".$row["regno"]."'"); $num_resultThree = mysql_num_rows($resultThree); for($j=0; $j<$num_resultThree; $j++) { $rowThree = mysql_fetch_array($resultThree); if($row["regno"] == $row["firstchoice"]) { $weight = 1; } if($row["regno"] == $row["secondchoice"]) { $weight = 2; } elseif($row["regno"] == $row["thirdchoice"]) { $weight = 3; } elseif($row["regno"] == $row["fourthchoice"]) { $weight = 4; } $resultFour = mysql_query("insert into '".$row["regno"]."' values '".$rowThree["name"]."','".$rowThree["points"]."','".$weight."'"); } } exit(); } </code> My problem is in the if..else statements. My code does not consider the last if...else statement Quote Link to comment https://forums.phpfreaks.com/topic/148566-cant-manipulate-my-last-database-column-within-phppliiiiiz-help/ Share on other sites More sharing options...
Adam Posted March 9, 2009 Share Posted March 9, 2009 Are the first two intentionally ifs and the second two else ifs? Adam Quote Link to comment https://forums.phpfreaks.com/topic/148566-cant-manipulate-my-last-database-column-within-phppliiiiiz-help/#findComment-780155 Share on other sites More sharing options...
joaca Posted March 9, 2009 Author Share Posted March 9, 2009 Sorry about that, I have changed the second if to ifelse. But that is certainly not the problem here Quote Link to comment https://forums.phpfreaks.com/topic/148566-cant-manipulate-my-last-database-column-within-phppliiiiiz-help/#findComment-780160 Share on other sites More sharing options...
Adam Posted March 9, 2009 Share Posted March 9, 2009 So what does happen if $row["regno"] doesn't equal $row["firstchoice"], and $row["regno"] doesn't equal $row["secondchoice"], and $row["regno"] doesn't equal $row["thirdchoice"] ? Syntactically, if the conditions said above are met there's no reason why the last 'if' statement wouldn't be run. The problem must lye within your own logic - or data. Try adding some debug like (just after: $rowThree = mysql_fetch_array($resultThree);): print $row['regno'] . '<br />'; print_r($rowThree); To see what values are being passed through the 'if' statements.. Adam Quote Link to comment https://forums.phpfreaks.com/topic/148566-cant-manipulate-my-last-database-column-within-phppliiiiiz-help/#findComment-780163 Share on other sites More sharing options...
joaca Posted March 9, 2009 Author Share Posted March 9, 2009 Sorry MrAdam, I must have made a mistake while copying the code to the forum. The if statements compare columns from two different tables. $row["regno"] is a column from a table that has schools and their registration numbers. $rowThree["firstchoice"] is a column from another table that has students and the choices of schools they wish to attend. My attempts to debug are not yielding anything positive. Quote Link to comment https://forums.phpfreaks.com/topic/148566-cant-manipulate-my-last-database-column-within-phppliiiiiz-help/#findComment-780173 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.