TimUSA Posted December 27, 2007 Share Posted December 27, 2007 How would I wrap this code up so that it was one variable? echo' <SELECT id="name" name="name[ ]" style="WIDTH: 160px" value ="'; if (isset($_POST['name[ ]'])) echo $_POST['name[ ]']; 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_assoc($result)){ echo '<option value="',$row['memberName'],'">',$row['memberName'],'</option>'; } } ++$x; } Link to comment https://forums.phpfreaks.com/topic/83418-variable-question/ Share on other sites More sharing options...
interpim Posted December 27, 2007 Share Posted December 27, 2007 are you going to change this dynamically? if not, why not just make a function call it stuff() function stuff(){ echo' <SELECT id="name" name="name[ ]" style="WIDTH: 160px" value ="'; if (isset($_POST['name[ ]'])) echo $_POST['name[ ]']; 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_assoc($result)){ echo '<option value="',$row['memberName'],'">',$row['memberName'],'</option>'; } } ++$x; }} Then where you want that particular piece to go. call the function <?php stuff(); ?> Link to comment https://forums.phpfreaks.com/topic/83418-variable-question/#findComment-424381 Share on other sites More sharing options...
TimUSA Posted December 27, 2007 Author Share Posted December 27, 2007 yes so, actually i just wanted to make it a variable so that it could be looped. so $test = stuff; and then loop with "while" Link to comment https://forums.phpfreaks.com/topic/83418-variable-question/#findComment-424382 Share on other sites More sharing options...
interpim Posted December 27, 2007 Share Posted December 27, 2007 This will call the function stuff() 10 times. $x=0; while($x<10){ stuff(); $x+1; } Link to comment https://forums.phpfreaks.com/topic/83418-variable-question/#findComment-424383 Share on other sites More sharing options...
TimUSA Posted December 27, 2007 Author Share Posted December 27, 2007 this poses the same problem i have been having. when ever i try to loop this code it returns blanks in the dropdown box. leave it with out the loop and it works fine and returns the appropriate database values here is the full code i am working with now: $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; function stuff() { echo' <SELECT id="name" name="name[ ]" style="WIDTH: 160px" value ="'; if (isset($_POST['name[ ]'])) echo $_POST['name[ ]']; 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_assoc($result)){ echo '<option value="',$row['memberName'],'">',$row['memberName'],'</option>'; } } ++$x; } $x=0; while($x<$times){ stuff(); ++$x; } Link to comment https://forums.phpfreaks.com/topic/83418-variable-question/#findComment-424385 Share on other sites More sharing options...
Sesquipedalian Posted December 28, 2007 Share Posted December 28, 2007 When I looked, this is what caught my eye: echo' <SELECT id="name" name="name[ ]" style="WIDTH: 160px" value ="'; if (isset($_POST['name[ ]'])) echo $_POST['name[ ]']; echo '" />'; I think you forgot a bracket after your if(). Link to comment https://forums.phpfreaks.com/topic/83418-variable-question/#findComment-424477 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.