Jump to content

creating a 1 to 100 in a table


lebedev9114

Recommended Posts

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 !

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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 ?

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.