TimUSA Posted December 27, 2007 Share Posted December 27, 2007 I created this code for SMF and TP so there is no mysql_connect as it is not needed. Just an example of what i am trying to do here. I have this code which pulls a list of names from a database in a selection box. I need to repeat it a designated number of times. What I am getting is the list in one box but not the rest. Any ideas? $query = "SELECT `memberName` FROM `smf_members` WHERE `ID_GROUP` IN (1, 9, 10, 11, 13) ORDER BY `memberName`;"; $result = mysql_query($query); $times = 13; $x = 0; while ($x < $times) { echo' <SELECT id="name" name="name[ ]" style="WIDTH: 160px" value ="'; echo '" />'; if(mysql_num_rows($result)) { // we have at least one user, so show all users as options in select form while($row = mysql_fetch_row($result)) { print("<option value=\"$row[0]\">$row[0]</option>"); } } else { print("<option value=\"\">No users created yet</option>"); } ++$x; } Quote Link to comment https://forums.phpfreaks.com/topic/83388-loop-question/ Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 May want to move your SELECT outside of the while loop unless you want 13 SELECT statements. Also, I dont see a closing /SELECT tag. Quote Link to comment https://forums.phpfreaks.com/topic/83388-loop-question/#findComment-424245 Share on other sites More sharing options...
TimUSA Posted December 27, 2007 Author Share Posted December 27, 2007 i do need 13 select statements Quote Link to comment https://forums.phpfreaks.com/topic/83388-loop-question/#findComment-424247 Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 This works for me, which is basically what you are doing minus the SQL <?php $x=0; $y=13; while ($x< $y) { echo "<select name='name'>"; echo "<option value=1>1</option>"; echo "</select>"; $x++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83388-loop-question/#findComment-424252 Share on other sites More sharing options...
Barand Posted December 28, 2007 Share Posted December 28, 2007 Once you have looped through the return results once any further fetch_row() calls return false as there is no more data to read. You need to rewind to the beginning of the resultset each time with mysql_data_seek($result, 0) Quote Link to comment https://forums.phpfreaks.com/topic/83388-loop-question/#findComment-424397 Share on other sites More sharing options...
TimUSA Posted December 28, 2007 Author Share Posted December 28, 2007 Thank you Thank you Thank you Thank you Thank you Thank you Quote Link to comment https://forums.phpfreaks.com/topic/83388-loop-question/#findComment-424403 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.