monkeypaw201 Posted May 24, 2008 Share Posted May 24, 2008 I have a query to display an appropriate rank according to how many hours they have. As such, i am having issues checking... the largest issue is that the check needs to be dynamic, in the way that it needs to check against a database for every rank in that table... <?php mysql_select_db($database_vamsys, $vamsys); $query_rankd = sprintf("SELECT * FROM vamsys_ranks ORDER BY hours ASC"); $rankd = mysql_query($query_rankd, $vamsys) or die(mysql_error()); $row_rankd = mysql_fetch_assoc($rankd); $totalRows_rankd = mysql_num_rows($rankd); mysql_select_db($database_vamsys, $vamsys); $query_rank = sprintf("SELECT * FROM vamsys_ranks ORDER BY hours ASC LIMIT 1,100"); $rank = mysql_query($query_rank, $vamsys) or die(mysql_error()); $row_rank = mysql_fetch_assoc($rank); $totalRows_rank = mysql_num_rows($rank); if($row_hour_count['hour_count'] > $row_rankd['hours']) { $rank1 = $row_rankd['title']; } do( elseif($row_hour_count['hour_count'] > $row_rank['hours']) { $rank1 = $row_rank['title']; } } while ($row_rank = mysql_fetch_assoc($rank)); ?> is what i tried but it gave me errors to no end... Link to comment https://forums.phpfreaks.com/topic/107114-ifelse-loop-not-working-is-there-a-better-way/ Share on other sites More sharing options...
BlueSkyIS Posted May 24, 2008 Share Posted May 24, 2008 what kind of errors? Link to comment https://forums.phpfreaks.com/topic/107114-ifelse-loop-not-working-is-there-a-better-way/#findComment-549121 Share on other sites More sharing options...
monkeypaw201 Posted May 24, 2008 Author Share Posted May 24, 2008 Parse error: syntax error, unexpected T_ELSEIF in /page.php on line 85 line 85: elseif($row_hour_count['hour_count'] > $row_rank['hours']) Link to comment https://forums.phpfreaks.com/topic/107114-ifelse-loop-not-working-is-there-a-better-way/#findComment-549124 Share on other sites More sharing options...
minidak03 Posted May 24, 2008 Share Posted May 24, 2008 if($row_hour_count['hour_count'] > $row_rankd['hours']) { $rank1 = $row_rankd['title']; } do( elseif($row_hour_count['hour_count'] > $row_rank['hours']) { $rank1 = $row_rank['title']; } } while ($row_rank = mysql_fetch_assoc($rank)); Look at where your do statement is it should be inside of your else if or completely outside of your if statement that is what is causing your error. Link to comment https://forums.phpfreaks.com/topic/107114-ifelse-loop-not-working-is-there-a-better-way/#findComment-549128 Share on other sites More sharing options...
BlueSkyIS Posted May 24, 2008 Share Posted May 24, 2008 yes, this is invalid. you can't continue an IF after starting a DO loop: do( elseif($row_hour_count['hour_count'] > $row_rank['hours']) { $rank1 = $row_rank['title']; } } while ($row_rank = mysql_fetch_assoc($rank)); can you explain the logic of what the code is supposed to do? Link to comment https://forums.phpfreaks.com/topic/107114-ifelse-loop-not-working-is-there-a-better-way/#findComment-549129 Share on other sites More sharing options...
monkeypaw201 Posted May 24, 2008 Author Share Posted May 24, 2008 The logic: I need to get a list of ranks and hours from the database and then compare them all to the user's hours and echo what rank that user is. ie bob has 7 hours, the 2 closest ranks are: rank1 and rank2 rank1 requires 0 hours rank2 requires 10 hours it will echo rank1 Link to comment https://forums.phpfreaks.com/topic/107114-ifelse-loop-not-working-is-there-a-better-way/#findComment-549131 Share on other sites More sharing options...
BlueSkyIS Posted May 24, 2008 Share Posted May 24, 2008 i would select all records, then loop over them. inside the loop, i would say "if hours >= 10, then rank = 2, else rank = 1" so i would only select once, then loop over that result, checking the hours field to set the rank at 1 or 2. Link to comment https://forums.phpfreaks.com/topic/107114-ifelse-loop-not-working-is-there-a-better-way/#findComment-549137 Share on other sites More sharing options...
monkeypaw201 Posted May 24, 2008 Author Share Posted May 24, 2008 i would select all records, then loop over them. inside the loop, i would say "if hours >= 10, then rank = 2, else rank = 1" so i would only select once, then loop over that result, checking the hours field to set the rank at 1 or 2. the problem is that the ranks are stored in the database and when the administrator changes the hour requirement it needs to update, the numbers can't be hard coded.. Link to comment https://forums.phpfreaks.com/topic/107114-ifelse-loop-not-working-is-there-a-better-way/#findComment-549140 Share on other sites More sharing options...
BlueSkyIS Posted May 24, 2008 Share Posted May 24, 2008 okay. so i would first select all ranks and load them into an array, using the lower cutoff for the key. then i would do a second select and compare the hours to the rank hours=>values stored in the array. Link to comment https://forums.phpfreaks.com/topic/107114-ifelse-loop-not-working-is-there-a-better-way/#findComment-549141 Share on other sites More sharing options...
monkeypaw201 Posted May 24, 2008 Author Share Posted May 24, 2008 uh... you lost me ??? ??? would you mind giving me a code example? maybe a link? Link to comment https://forums.phpfreaks.com/topic/107114-ifelse-loop-not-working-is-there-a-better-way/#findComment-549158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.