2tonejoe Posted December 3, 2007 Share Posted December 3, 2007 I have a database with table that has the name of the user alongside an integer from 0-4. I want to display between 0-4 <input name="text1" value="Text" type="text" size="30" /> based on the number I get from that table. . . how can I do this? I also want to name them 1, 2, 3 or 4 so that I can insert the data back into the database. . . Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 3, 2007 Share Posted December 3, 2007 <?php $query = mysql_query("SELECT number FROM table")or die(mysql_error()); $row = mysql_fetch_assoc($query); $number = $row['number']; //this is the number between 0-4 for ($i=0; $i<$number; $i++){ echo "<input name='text".$i."' value='Text' type='text' size='30' /><br>"; } ?> Quote Link to comment Share on other sites More sharing options...
grejon04 Posted December 3, 2007 Share Posted December 3, 2007 You may want to extend that so that it deletes (cleans up) tables when done with them, I've created tables dynamically, and you can get into trouble if they aren't cleaned up when they have no more use. j Quote Link to comment Share on other sites More sharing options...
revraz Posted December 3, 2007 Share Posted December 3, 2007 What table? Quote Link to comment Share on other sites More sharing options...
2tonejoe Posted January 17, 2008 Author Share Posted January 17, 2008 <?php $query = mysql_query("SELECT number FROM table")or die(mysql_error()); $row = mysql_fetch_assoc($query); $number = $row['number']; //this is the number between 0-4 for ($i=0; $i<$number; $i++){ echo "<input name='text".$i."' value='Text' type='text' size='30' /><br>"; } ?> The above code works great for me, but I now need it to count starting at "1". For instance, if $number is equal to 4, make four inputs named 1-4. If $number equals 6, make 6 inputs named 1-6, etc, etc. I changed the code to be the following: <?php $query = mysql_query("SELECT number FROM table")or die(mysql_error()); $row = mysql_fetch_assoc($query); $number = $row['number']; //this is the number between 0-4 for ($i=1; $i<$number; $i++){ echo "<input name='text".$i."' value='Text' type='text' size='30' /><br>"; } ?> but when $number is equal to 4, I only get three inputs named 1-3. ??? Quote Link to comment Share on other sites More sharing options...
mr_mind Posted January 17, 2008 Share Posted January 17, 2008 You did less than, not less than or equal to for ($i=1;$i<=$number;$i++){ print '<input name="text' . $i . '" value="Text" type="text" size="30" /><br>'; } Quote Link to comment Share on other sites More sharing options...
2tonejoe Posted January 17, 2008 Author Share Posted January 17, 2008 f*n awesome! thanks man! Quote Link to comment Share on other sites More sharing options...
mr_mind Posted January 17, 2008 Share Posted January 17, 2008 your welcome 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.