lebedev9114 Posted October 17, 2009 Share Posted October 17, 2009 hi guys I am a newb in php need some help. I have a table with 1 column and 100 rows and in each i want to do a 1-100. Can someone give me the full coding for this, please I can get it to work. I guess i am supposed to use some kind of an array loop or a While statement , but i am really stuck so a table would look like this : 1 2 3 4 .... and instead of writing each number in side the table row , i want to do it in php any help I am thankful for ! Quote Link to comment https://forums.phpfreaks.com/topic/178043-creating-a-1-to-100-in-a-table/ Share on other sites More sharing options...
waynew Posted October 17, 2009 Share Posted October 17, 2009 A simple example: Say you have a table called Example and one column called ID $i = 1; while($i < 101){ $query = "INSERT INTO Example(ID) VALUES('$i')"; mysql_query($query) or trigger_error(mysql_error()); $i++; } Although I must warn you of the overhead caused by such a script. If this is going to be a regular-running script (which I'm guessing it won't be), then you'll have to use prepared statements. If this is a once off script that will only run to serve as an example, then it's fine. Quote Link to comment https://forums.phpfreaks.com/topic/178043-creating-a-1-to-100-in-a-table/#findComment-938740 Share on other sites More sharing options...
lebedev9114 Posted October 17, 2009 Author Share Posted October 17, 2009 Actually I would want to work on a real web-site, so i am abit scared of the over loads. how about this : <table> while ($row = mysql_fetch_assoc($Result)) { ?> <th><?php echo $row['bookingname']; </table> Is it possible to do something like this inside a table with no database, only instead of getting a Result from the database, just have 1 - 100 autmoatically put in ? Quote Link to comment https://forums.phpfreaks.com/topic/178043-creating-a-1-to-100-in-a-table/#findComment-938745 Share on other sites More sharing options...
waynew Posted October 17, 2009 Share Posted October 17, 2009 Firstly; you should probably explain what you're attempting to achieve. Maybe then we'll be able to tell you the best way to do it. Your example above only prints out the value of a column called bookingname. It's not actually inserting anything? Quote Link to comment https://forums.phpfreaks.com/topic/178043-creating-a-1-to-100-in-a-table/#findComment-938747 Share on other sites More sharing options...
lebedev9114 Posted October 17, 2009 Author Share Posted October 17, 2009 Sorry, might be getting everyone confused ! : <tr> <td height="32" id="topth">1 </td> </tr> <tr> <td id="topth">2</td> </tr> <tr> <td id="topth">3</td> </tr> <tr> <td id="topth">4</td> </tr> <tr> <td id="topth">5</td> </tr> <tr> <td id="topth2">6</td> </tr> <tr> <td id="topth3">7</td> </tr> <tr> <td id="topth4">8</td> </tr> <tr> <td id="topth5">9</td> </tr> <tr> <td id="topth6">10</td> </tr> <tr> <td id="topth7">11</td> </tr> <tr> <td id="topth8">12</td> </tr> <tr> <td id="topth9">13</td> </tr> <tr> <td id="topth10">14</td> </tr> <tr> <td id="topth11">15</td> </tr> <tr> <td id="topth12">16</td> </tr> <tr> <td id="topth13">17</td> </tr> <tr> <td id="topth14">18</td> </tr> <tr> <td id="topth15">19</td> </tr> ... </table> I want to insert php into this, so i don't have to keep wirting out eveyr single number out Quote Link to comment https://forums.phpfreaks.com/topic/178043-creating-a-1-to-100-in-a-table/#findComment-938749 Share on other sites More sharing options...
Alex Posted October 17, 2009 Share Posted October 17, 2009 For the inserting example, this would be better, only 1 query no loop. mysql_query("INSERT INTO table (ID) VALUES (" . implode('),(', range(1, 100) . ");"); Quote Link to comment https://forums.phpfreaks.com/topic/178043-creating-a-1-to-100-in-a-table/#findComment-938750 Share on other sites More sharing options...
lebedev9114 Posted October 17, 2009 Author Share Posted October 17, 2009 Firstly; you should probably explain what you're attempting to achieve. Maybe then we'll be able to tell you the best way to do it. Your example above only prints out the value of a column called bookingname. It's not actually inserting anything? Basically that was a real table, i just didn't write it out completely. Basically I have a javascript code which sorts everything for me, but it sorts all columns in the table and the 1-100 i did not want to be sorted, so I wanted to make a new table on the left of this one having 1-100. here is how it looks like : www.etromnia.com i just uploaded so the sorting is not working yet. Quote Link to comment https://forums.phpfreaks.com/topic/178043-creating-a-1-to-100-in-a-table/#findComment-938751 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.