MoFish Posted April 19, 2007 Share Posted April 19, 2007 hello everyone. I currently have a variable called $NumPlayers which contains a number between 4 and 8; depending on this value; i would like to create this amount of listboxes on my page. For example if the value of $NumPlayers is 6; I would like 6 listboxes to be displayed on the page with names such as "Lstbox1" "Lstbox2". I'm a bit clueless where to start; and was hoping someone could point me in the right direction. Thanks alot, MoFish Quote Link to comment Share on other sites More sharing options...
cx323 Posted April 19, 2007 Share Posted April 19, 2007 untested, but it should be something like this: <?php for($i=1;$i<=$NumPlayers;++$i){ echo '<select name="LstBox'.$i.'> <option value="">Choice</option> </select>'; } ?> Quote Link to comment Share on other sites More sharing options...
MoFish Posted April 19, 2007 Author Share Posted April 19, 2007 seems to work a treat. thank you very much. Quote Link to comment Share on other sites More sharing options...
MoFish Posted April 19, 2007 Author Share Posted April 19, 2007 it generates the right amount of boxes; but for some reason there is no values in the boxes. Quote Link to comment Share on other sites More sharing options...
cx323 Posted April 19, 2007 Share Posted April 19, 2007 it looks like i forgot a quote. it should be: <?php for($i=1;$i<=$NumPlayers;++$i){ echo '<select name="LstBox'.$i.'"> <option value="">Choice</option> </select>'; } ?> Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 19, 2007 Share Posted April 19, 2007 it looks like i forgot a quote. it should be: <?php for($i=1;$i<=$NumPlayers;++$i){ echo '<select name="LstBox'.$i.'"> <option value="">Choice</option> </select>'; } ?> your code is a little messed up. you want the select to be outside of the for loop. also there is even a little more missing as well... the value="" cannot be empty, otherwise it defeats the purpose of having a dropdown menu. no values will pass with the form from the dropdown menu. i'm not sure what value you'd put in there, but it needs to have one. my guess is you want it to look like this: <?php echo "<select name=\"dropdown\">\n"; for($i = 1; $i <= $NumPlayers; $i++){ echo "<option value=\"{$i}\">{$i} player". (($i != 1) ? ('s') : ('')) ."\n"; } echo "</select>\n"; ?> Quote Link to comment Share on other sites More sharing options...
MoFish Posted April 19, 2007 Author Share Posted April 19, 2007 hello again. boo_lolly; i tested your code, and it puts the number of values into one listbox instead of generating the number of individual listboxes; cx323's code seemed to work in the correct mannor. my next problem is populating these listboxes with data from a database. i want each listbox to be populated with the same list of data. I tryed the following code which worked well for the first listbox; but not the rest. once these have been populated i hope to be able to select values from them; and submitted it in a form. $result = mysql_query("SELECT * FROM `tbl_players`"); for($i=1;$i<=$NumPlayers;++$i){ echo '<select name="LstBox'.$i.'">'; while ($myrow = mysql_fetch_array($result)) { $opt = $myrow['PlayerName']; echo "<option>$opt</option> "; } echo '</select>'; } Quote Link to comment Share on other sites More sharing options...
cx323 Posted April 19, 2007 Share Posted April 19, 2007 do you mean like this: $result = mysql_query("SELECT * FROM `tbl_players`"); while ($myrow = mysql_fetch_array($result)) { $opt .= '<option value="'.$myrow['PlayerName'].'">'.$myrow['PlayerName'].'</option>'; } for($i=1;$i<=$NumPlayers;++$i){ echo '<select name="LstBox'.$i.'">'.$opt.'</select>'; } Quote Link to comment Share on other sites More sharing options...
MoFish Posted April 19, 2007 Author Share Posted April 19, 2007 exactly like that!!! perfect!!!! thanks so much. Quote Link to comment Share on other sites More sharing options...
MoFish Posted April 20, 2007 Author Share Posted April 20, 2007 sorry, didnt want to make a thread for something small like this ... why does the following formula not work? $1stPlaceWinnings = $PlayerNumber * $BuyInPrice - $BuyInPrice; Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in D:\wampnew\www\APL\ConfirmAndReport.php on line 91 the values are for example: $PlayerNumber = 7 $BuyInPrice = 5 so - 7 * 5 = 35 then - 5 = 30 30 is the answer i need, but the above doesnt seem to work. Quote Link to comment Share on other sites More sharing options...
Moon-Man.net Posted April 20, 2007 Share Posted April 20, 2007 $1stPlaceWinnings -- Remove the 1 from the start of your variable. I donno, why, but that does it -- Nathan Quote Link to comment Share on other sites More sharing options...
cx323 Posted April 20, 2007 Share Posted April 20, 2007 $1stPlaceWinnings -- Remove the 1 from the start of your variable. I donno, why, but that does it -- Nathan it's because variable names must start with a letter or underscore Quote Link to comment 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.